TGraphic (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example demonstrates the use of some methods and properties available for TBitmap and TGraphic objects.

Code

__fastcall TMainForm::TMainForm(TComponent* Owner) : TForm(Owner)
{
  /* Change the AlphaFormat property */
  MyImage1->Picture->Bitmap->AlphaFormat = afPremultiplied;
  /* Check whether the graphic supports partial transparency.
     This is a read-only property */
  if (MyImage1->Picture->Graphic->SupportsPartialTransparency)
  {
	Memo1->Lines->Add("The graphic supports partial transparency");
  }
  else
  {
	Memo1->Lines->Add("The graphic does not support partial transparency");
  }
}

void __fastcall TMainForm::btCompareClick(TObject *Sender)
{
  /* Compare the contents of two graphics */
  if (MyImage1->Picture->Graphic->Equals((TObject*)MyImage2->Picture->Graphic))
  {
	Memo1->Lines->Add("Same image");
  }
  else
  {
	Memo1->Lines->Add("Different images");
  }
}

void __fastcall TMainForm::btLoadClick(TObject *Sender)
{
  OpenPictureDialog1->Execute();
  /* Load a picture from a file */
  MyImage2->Picture->LoadFromFile(String(OpenPictureDialog1->FileName));
}

Uses