RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TImage.Picture Property

Specifies the image that appears on the image control.

Pascal
property Picture: TPicture;
C++
__property TPicture Picture;

Use Picture to specify the image for the TImage component. Picture is a reference to a TPicture object. Use properties and methods of TPicture to specify a bitmap, icon, metafile, or user-defined graphic to be displayed by the image control. 

Setting Picture at design time brings up the Picture Editor, which can be used to specify the file that contains the image.  

C++ Examples: 

 

/*
This example uses an image, a button, and a shape component
on a form. When the user clicks the button, an image of the
form is stored in the FormImage variable and copied to the
Clipboard. The image of the form is then copied back to
the image component, producing an interesting result,
especially if the button is clicked multiple times.  Add
ExtCtrls, StdCtrls, and Clipbrd to the uses clause.
}
*/

#include <Clipbrd.hpp>

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Graphics::TBitmap *FormImage = GetFormImage();
  try
  {
    Clipboard()->Assign(FormImage);
    Image1->Picture->Assign(Clipboard());
  }
  __finally
  {
    delete FormImage;
  }
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  Shape1->Shape = stEllipse;
  Shape1->Brush->Color = clLime;
  Image1->Stretch = true;
}
/*
The following code draws the graphic in Picture1 in the
top-left corner PaintBox1.  Place a TPaintBox in the form 
and a TImage in the form that contains a picture.
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  PaintBox1->Canvas->Draw(0,0, Image1->Picture->Graphic);
}

 

Delphi Examples: 

{
This example uses an image, a button, and a shape component
on a form. When the user clicks the button, an image of the
form is stored in the FormImage variable and copied to the
Clipboard. The image of the form is then copied back to
the image component, producing an interesting result,
especially if the button is clicked multiple times.  Add
ExtCtrls, StdCtrls, and Clipbrd to the uses clause.
}
procedure TForm1.Button1Click(Sender: TObject);
var
  FormImage: TBitmap;
begin
  FormImage := GetFormImage;
  try
    Clipboard.Assign(FormImage);
    Image1.Picture.Assign(Clipboard);
  finally
    FormImage.Free;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Shape1.Shape := stEllipse;
  Shape1.Brush.Color := clLime;
  Image1.Stretch := True;
end; 

 

{
The following code draws the graphic in Picture1 in the
top-left corner PaintBox1.  Place a TPaintBox in the form 
and a TImage in the form that contains a picture.
}
procedure TForm1.Button1Click(Sender: TObject);
begin
  PaintBox1.Canvas.Draw(0,0, Image1.Picture.Graphic);
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!