RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TJPEGImage.Assign Method

Copies the jpeg image object and creates a new reference to the internal data source object.

Pascal
procedure Assign(Source: TPersistent); override;
C++
virtual __fastcall Assign(TPersistent * Source);

Assign copies the jpeg image contained in Source to the jpeg image object. Assign then calls the inherited Assign. Assign creates a new link to the internal jpeg data source by which the jpeg image objects do reference counting and handle sharing.

Tip: To draw on a jpeg image, Assign the jpeg image to a bitmap, and then draw on that.
Note: An object of one type can always be assigned to another object of the same type. Also, the Source can be of type TPicture if the Graphic property of the picture is a jpeg image or a bitmap.
 

C++ Examples: 

 

/*
This example converts a bitmap image to a jpeg file by using
the Assign method.  This example requires a button and two
images.  One image must have it's Picture property loaded
with a bitmap at design time.
*/

#include <Jpeg.hpp>

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  //Requires "jpeg.hpp" to be included in the source file
  TJPEGImage *jp = new TJPEGImage();
  try
  {
    jp->Assign(Image1->Picture->Bitmap);
    jp->SaveToFile("..\\factory.jpg");
    Image2->Stretch = True;
    Image2->Picture->LoadFromFile("..\\factory.jpg");
  }
  __finally
  {
    delete jp;
  }
}

 

Delphi Examples: 

{
This example converts a bitmap image to a jpeg file by using
the Assign method.  This example requires a button and two
images.  One image must have it's Picture property loaded
with a bitmap at design time.
}
uses Jpeg;

procedure TForm1.Button1Click(Sender: TObject);
var
  jp: TJPEGImage;  //Requires the "jpeg" unit added to "uses" clause.
begin
  jp := TJPEGImage.Create;
  try
    with jp do
    begin
      Assign(Image1.Picture.Bitmap);
      SaveToFile('factory.jpg');
      Image2.Stretch := True;
      Image2.Picture.LoadFromFile('factory.jpg');
    end;
  finally
    jp.Free;
  end;
end;

 

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