Recent

Author Topic: [CLOSED] BGRABitmap Free  (Read 2298 times)

pcurtis

  • Hero Member
  • *****
  • Posts: 939
[CLOSED] BGRABitmap Free
« 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?
« Last Edit: January 25, 2022, 11:06:17 pm by pcurtis »
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

Josh

  • Hero Member
  • *****
  • Posts: 932
Re: BGRABitmap Free
« Reply #1 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;
Development Installation Lazarus 1.3, FPC 2.7.1,Windows 7/8 32/64, OSX, *nix

Test Environment Lazarus & FPC Trunk on Windows and OSX (Cocoa Mainly on OSX). Testing also Crosscompile windows to OSX.. 
Any posts made from 2015 will be based on Lazarus Trunk.

pcurtis

  • Hero Member
  • *****
  • Posts: 939
Re: BGRABitmap Free
« Reply #2 on: January 25, 2022, 06:59:52 pm »
OK Thanks that works, but with tbitmap I don't need it. Why?
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

winni

  • Hero Member
  • *****
  • Posts: 3057
Re: BGRABitmap Free
« Reply #3 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

pcurtis

  • Hero Member
  • *****
  • Posts: 939
Re: BGRABitmap Free
« Reply #4 on: January 25, 2022, 11:05:09 pm »
Enough said.
Built for *nix, pray it works on other OS's.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

winni

  • Hero Member
  • *****
  • Posts: 3057
Re: [CLOSED] BGRABitmap Free
« Reply #5 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

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


pcurtis

  • Hero Member
  • *****
  • Posts: 939
Re: [CLOSED] BGRABitmap Free
« Reply #6 on: January 25, 2022, 11:56:59 pm »
So how do you use center, stretch, proportional properties of TImage?
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

winni

  • Hero Member
  • *****
  • Posts: 3057
Re: [CLOSED] BGRABitmap Free
« Reply #7 on: January 26, 2022, 12:02:13 am »
Hi!

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

Winni

pcurtis

  • Hero Member
  • *****
  • Posts: 939
Re: [CLOSED] BGRABitmap Free
« Reply #8 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.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

Josh

  • Hero Member
  • *****
  • Posts: 932
Re: [CLOSED] BGRABitmap Free
« Reply #9 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;            
Development Installation Lazarus 1.3, FPC 2.7.1,Windows 7/8 32/64, OSX, *nix

Test Environment Lazarus & FPC Trunk on Windows and OSX (Cocoa Mainly on OSX). Testing also Crosscompile windows to OSX.. 
Any posts made from 2015 will be based on Lazarus Trunk.

 

TinyPortal © 2005-2018