Lazarus

Programming => Graphics => Graphics and Multimedia => BGRABitmap and LazPaint => Topic started by: pcurtis on January 25, 2022, 05:11:03 pm

Title: [CLOSED] BGRABitmap Free
Post by: pcurtis on January 25, 2022, 05:11:03 pm
When I do this

Code: Pascal  [Select][+][-]
  1. procedure TfrmMain.btnOKClick(Sender: TObject);
  2. var
  3.   MyImage: TBGRABitmap;
  4. begin
  5.   MyImage := TBGRABitmap.Create;
  6.   MyImage.LoadFromFile('1.bmp');
  7.   Image1.Picture.Bitmap := MyImage.Bitmap;
  8.   MyImage.Free;
  9. end;
  10.  

When MyImage is freed the Imagebox shows a black square. With a TBitmap it works fine.

Am I missing something?
Title: Re: BGRABitmap Free
Post by: Josh on January 25, 2022, 06:46:12 pm
hi try to update image1, before you free MyImage
Code: Pascal  [Select][+][-]
  1. MyImage := TBGRABitmap.Create('1.bmp');
  2.  // MyImage.LoadFromFile('1.bmp');
  3.   Image1.Picture.Bitmap:=MyImage.Bitmap;
  4.   Image1.Update;
  5.   MyImage.Free;
Title: Re: BGRABitmap Free
Post by: pcurtis on January 25, 2022, 06:59:52 pm
OK Thanks that works, but with tbitmap I don't need it. Why?
Title: Re: BGRABitmap Free
Post by: winni on January 25, 2022, 09:21:37 pm
Hi!

This is a problem of the widget set.

With linux / gtk2 it is not necessary.

Winni
Title: Re: BGRABitmap Free
Post by: pcurtis on January 25, 2022, 11:05:09 pm
Enough said.
Built for *nix, pray it works on other OS's.
Title: Re: [CLOSED] BGRABitmap Free
Post by: winni on January 25, 2022, 11:26:27 pm
Hi!

Just do it how it is shown in the tutorials:

https://wiki.freepascal.org/BGRABitmap_tutorial (https://wiki.freepascal.org/BGRABitmap_tutorial)

I pray for nothing.

But that is the correct way to use it:

Code: Pascal  [Select][+][-]
  1. MyImage.Draw(Image1.Canvas,0,0);
  2. MyImage.free;
  3.  

Winni

Title: Re: [CLOSED] BGRABitmap Free
Post by: pcurtis on January 25, 2022, 11:56:59 pm
So how do you use center, stretch, proportional properties of TImage?
Title: Re: [CLOSED] BGRABitmap Free
Post by: winni on January 26, 2022, 12:02:13 am
Hi!

If your google is broken then use the "search" option of this forum.

Winni
Title: Re: [CLOSED] BGRABitmap Free
Post by: pcurtis on January 26, 2022, 12:17:34 am
My Google works fine.

Why reinvent the wheel?

Code: Pascal  [Select][+][-]
  1.   Image1.Picture.Bitmap:=MyImage.Bitmap;
  2.   Image1.Update;
  3.  

Works fine.
Title: Re: [CLOSED] BGRABitmap Free
Post by: Josh on January 26, 2022, 05:54:12 pm
you could use an intermeddiate bitmap to hold the image; should work on all os's. no update should be needed.
Code: Pascal  [Select][+][-]
  1. var
  2.   bmp:tbitmap;
  3.   MyImage: TBGRABitmap;
  4.  
  5. begin
  6.   MyImage := TBGRABitmap.Create;
  7.   bmp:=tbitmap.Create;
  8.   myimage.LoadFromFile('1.bmp');
  9.   bmp.SetSize(myimage.Width,myimage.Height);
  10.   bmp.Canvas.Draw(0,0,myimage.Bitmap);
  11.   image1.Picture.Bitmap:=bmp;
  12.   MyImage.Free;
  13.   bmp.free;
  14. end;            
TinyPortal © 2005-2018