Resizing jpeg image after conversion from bitmap does not work

I convert a bitmapto jpegand want to display the result in the image using different scales. I am using the following code that works great.

procedure TForm1.Button1Click(Sender: TObject);
var
  Bmp: TBitmap;
  Jpg: TJPEGImage;
begin
  Bmp := TBitmap.Create;
  Bmp.PixelFormat := pf32bit;
  Jpg := TJPEGImage.Create;
  try
    Bmp.LoadFromFile('0C310060.bmp');
    Jpg.Assign(Bmp);
    Jpg.SaveToFile('0C310060.jpg');
    Image1.Picture.Assign(Jpg);
    TJPEGImage(Image1.Picture.Graphic).Scale := jsEighth;
  finally
    Jpg.Free;
    Bmp.Free;
  end;
end;

I do not need a file jpegon disk. However, if I delete the line Jpg.SaveToFile('0C310060.jpg'), I get an access violation. Why? What is doing Jpg.SaveToFilebehind the scenes to prevent access violation?

+4
source share

Source: https://habr.com/ru/post/1692148/


All Articles