Recent

Author Topic: Display BGRABitmap to TImage (Solved)  (Read 2000 times)

Dzandaa

  • New Member
  • *
  • Posts: 13
Display BGRABitmap to TImage (Solved)
« on: July 09, 2021, 05:57:30 pm »
Hello, I'm new to Lazarus for a Week (Migrating from C#).
And I'm also French Speaking, so...

Lazarus version 2.0.12 (Windows, Mac, Linux)

I am converting one of my program from C# to Lazarus.
First I use Graphics32.

Works fine on Windows and Linux, but not on Mac.

So I try with BGRABitmap

My problem:
with 3 BGRABitmaps of the same size

I want to draw the second  on the first and draw the 3rd with transparency on the first.
Then display the result on a TImage with Stretch and proportional enabled

Converting the resulting BGRABitmap to Bitmap is also a solution, but I don't know how to do it.

var
  FileName, Status: String;
  Picture: TBGRABitmap;  // Temp Picture
begin
  if OpenPicture.Execute then
  begin
    FileName := OpenPicture.FileName;
    Picture := TBGRABitmap.Create(FileName);   

O.K. here, but then I'm stuck... :)

Thank you.




« Last Edit: July 10, 2021, 12:08:57 pm by Dzandaa »

winni

  • Hero Member
  • *****
  • Posts: 2660
Re: Display BGRABitmap to TImage
« Reply #1 on: July 09, 2021, 06:32:14 pm »
Code: Pascal  [Select][+][-]
  1. var bmp1, bmp2,bmp3, tmp: TBGRAbitmap;
  2.  
  3. ....
  4. bmp1.putimage (0,0,bmp2,dmset);
  5. bmp1.putimage (0,0,bmp3, dmDrawWithTransparency);
  6. tmp := TBGRAbitmap.create;
  7. BGRAReplace(tmp, bmp1.Resample(Image1.width,image1.Height) );
  8. tmp.draw(Image1.Canvas, 0,0,true);
  9. tmp.free;
  10. ......

Have a look at the parameter TDrawMode in putimage, where possible values are:
Code: Pascal  [Select][+][-]
  1. TDrawMode = (
  2.     dmSet,
  3.     dmSetExceptTransparent,
  4.     dmLinearBlend,
  5.     dmDrawWithTransparency,
  6.     dmXor);

Winni
 

Dzandaa

  • New Member
  • *
  • Posts: 13
Re: Display BGRABitmap to TImage
« Reply #2 on: July 10, 2021, 12:08:13 pm »
Thank you for the code.

Just modified to:

Code: Pascal  [Select][+][-]
  1. Picture : TBGRAbitmap // The resulting picture
  2. PBFrame : TImage  // Center, Proportional, Stretch, StretchInEnabled, StretchOutEnabled, Anchors: Bottom, Right, Left, Top
  3. TBit: TBitmap;  
  4.  
  5.     TBit := TBitmap.Create;
  6.     try
  7.      TBit.PixelFormat := pf24bit;
  8.      TBit.Width := Picture.Width;
  9.      TBit.Height := Picture.Height;
  10.      Picture.draw(TBit.Canvas, 0,0,true);
  11.      PBFrame.Picture.Assign(TBit) ;
  12.     finally
  13.     end;    
  14.  
And It's working!!!

Thank you very much.
« Last Edit: July 10, 2021, 03:54:39 pm by Dzandaa »

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Display BGRABitmap to TImage (Solved)
« Reply #3 on: July 10, 2021, 12:27:11 pm »
Please, Dzandaa, in the future use "code" tags to post code snippets; it makes it easier to read and copy for testing/correcting/using it outside the browser (like e.g. in Lazarus) and prevents parts of it being taken as BBCode (e.g. "SomeArray[i] ..." would start writing in italics rather than displaying as an array index)
Thanks ;)
« Last Edit: July 10, 2021, 12:30:01 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Dzandaa

  • New Member
  • *
  • Posts: 13
Re: Display BGRABitmap to TImage (Solved)
« Reply #4 on: July 10, 2021, 03:55:05 pm »
Done!!!
Thank you.

 

TinyPortal © 2005-2018