[Lazarus] A bitmap strange issue

Luca Olivetti luca at wetron.es
Sat Apr 21 18:06:44 CEST 2018


El 21/04/18 a les 17:18, Giuliano Colla via Lazarus ha escrit:
>
> Here's a snippet of code used to show the issue:
>
>> procedure TForm1.Button1Click(Sender: TObject); var Filename: String; 
>> begin if OpenPictureDialog1.Execute then begin // MyBitmap := 
>> Image1.Picture.Bitmap; <-------This causes a sigsev in FreeImage

If you follow the implementation of Image1.Picture.LoadFromFile you'll 
see that it frees the current bitmap, that's the cause of the sigsev.
If you want to save the bitmap for later use, you should probably make a 
copy instead.

>> Filename:= OpenPictureDialog1.FileName; 
>> Image1.Picture.LoadFromFile(Filename); If assigned(MyBitmap) then 
>> begin MyBitmap.FreeImage; FreeAndNil(MyBitmap); end; end; end; 
>> procedure TForm1.Button2Click(Sender: TObject); begin If not 
>> Assigned(MyBitmap) then MyBitmap:= TBitmap.Create; MyBitmap.Width:= 
>> Image1.Width; MyBitmap.Height:= Image1.Height; 
>> MyBitmap.Canvas.Brush.Color:= clNavy; MyBitmap.Canvas.Brush.Style:= 
>> bsSolid; 
>> MyBitmap.Canvas.FillRect(0,0,MyBitmap.Width,MyBitmap.Height); 
>> Image1.Picture.Bitmap := MyBitmap;

And this assignment makes a copy of MyBitmap

>> //MyBitmap.FreeImage; Useless FreeAndNil(MyBitmap); end; 

Bye

-- 
Luca Olivetti
Wetron Automation Technology http://www.wetron.es/
Tel. +34 93 5883004 (Ext.3010)  Fax +34 93 5883007



More information about the Lazarus mailing list