Recent

Author Topic: [solved] TBGRABitmap.MakeBitmapCopy() => black TBitmap  (Read 300 times)

Aidex

  • Jr. Member
  • **
  • Posts: 75
[solved] TBGRABitmap.MakeBitmapCopy() => black TBitmap
« on: April 11, 2021, 05:29:41 pm »
Hi!
I am trying to convert a TBGRABitmap to a TBitmap.
Unfortunately, the result is always a black content.
What am I doing wrong?
I have also tried with .Draw via Canvas, but I also get only a black content.
I'm using Lazarus v2.0.10 on Win64 and its supplied BGRABitmap package (v11.3.1.0).
Thanks in advance for any hints.

Code: Pascal  [Select][+][-]
  1. uses BGRABitmap, BGRABitmapTypes;
  2.  
  3. procedure TForm1.Button1Click(Sender: TObject);
  4. var
  5.     BGRABmp: TBGRABitmap;
  6.     FpBmp: TBitmap;
  7. begin
  8.   BGRABmp:=TBGRABitmap.Create;
  9.   BGRABmp.LoadFromFile('Test.bmp');
  10.   BGRABmp.SaveToFile('Test out1.bmp');  // works
  11.  
  12.   FpBmp:=BGRABmp.MakeBitmapCopy($FFFFFF);
  13.   FpBmp.SaveToFile('Test out2.bmp');  // correct pixel size and file size, but black content
  14.   FpBmp.Destroy;
  15.  
  16.   BGRABmp.Destroy;
  17. end;
  18.  
« Last Edit: April 11, 2021, 06:16:25 pm by Aidex »

GetMem

  • Hero Member
  • *****
  • Posts: 4017
Re: TBGRABitmap.MakeBitmapCopy() => black TBitmap
« Reply #1 on: April 11, 2021, 05:43:48 pm »
Hi Aidex,

FpBmp is sleeping. Every time you modify the bitmap's canvas, as in MakeBitmapCopy, you have to remind TBitmap that the canvas has changed.   :D
The fix is simple, just add Changed after MakeBitmapCopy, like this:
Code: Pascal  [Select][+][-]
  1. //..
  2.   FpBmp:=BGRABmp.MakeBitmapCopy($FFFFFF);
  3.   FpBmp.Canvas.Changed;
  4. //..
« Last Edit: April 11, 2021, 05:45:26 pm by GetMem »

Aidex

  • Jr. Member
  • **
  • Posts: 75
Re: TBGRABitmap.MakeBitmapCopy() => black TBitmap
« Reply #2 on: April 11, 2021, 06:06:39 pm »
Finally it works!
Many, many thanks! :)

winni

  • Hero Member
  • *****
  • Posts: 2331
Re: [solved] TBGRABitmap.MakeBitmapCopy() => black TBitmap
« Reply #3 on: April 11, 2021, 06:21:04 pm »
Hi!

All ways lead to Rome ...

Two other ways:

a)
Code: Pascal  [Select][+][-]
  1. BGRAbmp.draw (FpBmp.canvas,0,0);

b)
Code: Pascal  [Select][+][-]
  1. R := Rect(0,0,FpBmp.width, FpBmp.height);
  2. FpBmp.Canvas.CopyRect (R, BGRAbmp.canvas,R);

Winni
« Last Edit: April 11, 2021, 06:23:14 pm by winni »

circular

  • Hero Member
  • *****
  • Posts: 3712
    • Personal webpage
Re: [solved] TBGRABitmap.MakeBitmapCopy() => black TBitmap
« Reply #4 on: April 12, 2021, 12:40:04 am »
Hmm strange, MakeBitmapCopy is intended to give a savable image. If you have a fix to BGRABitmap to propose, it would be welcome.
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018