Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear a jpeg image?

Tags:

delphi

How to clear a TJPEGImage image?

The JPG.Width := 0 trick won't work. Also I don't want to create an empty bitmap (0x0 pixels) and assign it to the jpeg.

like image 254
Server Overflow Avatar asked Dec 17 '12 18:12

Server Overflow


2 Answers

You might use something like this (the interposed class is used here to access the protected methods):

type
  TJPEGImage = class(jpeg.TJPEGImage);

implementation

procedure TForm1.Button1Click(Sender: TObject);
var
  JPEGImage: TJPEGImage;
begin
  JPEGImage := TJPEGImage.Create;
  try
    // this should recreate the internal bitmap
    JPEGImage.NewBitmap;
    // this should recreate the internal image stream
    JPEGImage.NewImage;
    // here the memory used by the image should be released
  finally
    JPEGImage.Free;
  end;
end;
like image 129
TLama Avatar answered Oct 13 '22 04:10

TLama


If you don't want to use FreeAndNil and keep the image empty...

Procedure EmptyJPG(jpg:TJpegImage);
var
 j:TJpegImage;
begin
  j := TJpegImage.Create;
  try
    jpg.Assign(j);
  finally
    j.Free;
  end;
end;
like image 36
bummi Avatar answered Oct 13 '22 03:10

bummi