TJPEGImageAssign (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

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 its Picture property loaded with a bitmap at design time.

Code

uses Jpeg;

procedure TForm1.Button1Click(Sender: TObject);
var
  jp: TJPEGImage;  //Requires the jpeg unit added to the 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;

Uses