Recent

Author Topic: Question about merging images with BGRABitmap:  (Read 1268 times)

stab

  • Full Member
  • ***
  • Posts: 234
Question about merging images with BGRABitmap:
« on: February 02, 2022, 03:16:08 pm »
Have tried to merge several images but the result shown is
always only the last merged image.
Understand that I'm using BGRABitmap in some wrong way, but
can't figure what I'm doing wrong.

Have tried to follow Add a painting handler in tutorial 5, but apperently
not understood it.

In my program I have a TImage showing a map from which I want to extract
colors by clicking in the image. For every pixel clicked, I create
a BGRABitmap containing only current selected color, that then is inserted into a dynamic array of TBGRABitmap.
At the same time the current color is drawn in a DrawGrid.
Associated with the DrawGrid is a CheckListBox.
When colors are selected by checking the CheckListBox, colors should
be merged together and the result be displayed in another TImage.
My code is as follows:
Code: Pascal  [Select][+][-]
  1. procedure TfrmExtractElevationCurves.chklbxColorsClickCheck(Sender: TObject);
  2. var
  3.   n : integer;
  4.   bitmap, bmap : TBGRABitmap;
  5. begin
  6.   Image1.Picture.Bitmap.Canvas.Brush.Color := clWhite;
  7.   Image1.Picture.Bitmap.Canvas.FillRect(0, 0, Image1.Width, Image1.Height);
  8.  
  9.   bmap := TBGRABitmap.Create(Image1.Width, Image1.Height);
  10.   try
  11.     n := 0;
  12.     while n < chklbxColors.Count do
  13.     begin
  14.       if chklbxColors.Checked[n] then
  15.       begin
  16.         bitmap := FLayers[n];
  17.         bmap.PutImage(0, 0, bitmap, dmDrawWithTransparency);
  18.       end;
  19.       Inc(n);
  20.     end;
  21.     bmap.Draw(Image1.Picture.Bitmap.Canvas, 0, 0);
  22.   finally
  23.     FreeAndNil(bmap);
  24.   end;
  25. end;
  26.  

Any help about what I have done wrong appreciated! %)
« Last Edit: February 02, 2022, 09:08:59 pm by stab »

lainz

  • Hero Member
  • *****
  • Posts: 4468
    • https://lainz.github.io/
Re: Question about merging images with BGRABitmap:
« Reply #1 on: February 02, 2022, 04:34:28 pm »
Attach a compilable demo, so we can play with your code too =)

stab

  • Full Member
  • ***
  • Posts: 234
Re: Question about merging images with BGRABitmap:
« Reply #2 on: February 05, 2022, 01:32:38 pm »
Did notice that one should use BlendImage instead of PutImage ::)

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Question about merging images with BGRABitmap:
« Reply #3 on: February 05, 2022, 01:52:39 pm »
Hi!

If you want to get the effect of transparency you have to set the alpha value for selected pixels or the whole image. An alpha value of zero means trasnsparent, 255  means opaque. So 127 is semi-transparent.

For a single TBGRApixel you  can do
Code: Pascal  [Select][+][-]
  1. pix.alpha := [byte];

If you want to fill the whole bitmap with an alpha value you can use

Code: Pascal  [Select][+][-]
  1. procedure TBGRAbitmap.AlphaFill(alpha: byte);
  2.  

And read the tutorial #5 again. In  case of questions specify your problem.

Winni






circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: Question about merging images with BGRABitmap:
« Reply #4 on: February 05, 2022, 04:03:09 pm »
Did notice that one should use BlendImage instead of PutImage ::)
It depends what you want to do. BlendImage with boTransparent is the same as PutImage.
Conscience is the debugger of the mind

stab

  • Full Member
  • ***
  • Posts: 234
Re: Question about merging images with BGRABitmap:
« Reply #5 on: February 05, 2022, 04:29:20 pm »
OK, I see, thank you

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Question about merging images with BGRABitmap:
« Reply #6 on: February 05, 2022, 04:42:52 pm »
Hi!

TBGRAbitmap.BlendImage is for blending bitmaps at the whole in different ways to achieve special effects. Look at the blend parameter whith values like
boNiceGlow, boSoftLight, boHardLight


If you want to merge 2 colors then both pixels should have an alpha value of 127.

Winni

PS.:  In the unit BGRAfilters there are this two functions to merge the colors of  pixels:


Code: Pascal  [Select][+][-]
  1. function MergeBGRA(c1, c2: TBGRAPixel): TBGRAPixel; overload;
  2.  
  3. function MergeBGRA(c1: TBGRAPixel; weight1: integer; c2: TBGRAPixel; weight2: integer): TBGRAPixel; overload;
  4.  
« Last Edit: February 05, 2022, 04:51:04 pm by winni »

 

TinyPortal © 2005-2018