Lazarus

Programming => Graphics => Graphics and Multimedia => BGRABitmap and LazPaint => Topic started by: pcurtis on May 25, 2021, 10:53:03 am

Title: [SOLVED] BGRABitmap blur effect
Post by: pcurtis on May 25, 2021, 10:53:03 am
I use BGRA to create a bitmap

Code: Pascal  [Select][+][-]
  1. MyBM := TBGRABitmap.Create(1280, 720, clBtnFace);
  2.  

and

Code: Pascal  [Select][+][-]
  1. MyBM.PutImage(...., dmFastBlend);
  2.  

to insert another  image.

My question is how can I blur this second image? (It will be used as a backdrop for another image)
Title: Re: BGRABitmap blur effect
Post by: winni on May 25, 2021, 12:55:18 pm
Hi!

Look in the Unit BGRAbitmap:

Code: Pascal  [Select][+][-]
  1. function FilterBlurRadial
  2. function FilterBlurMotion
  3. function FilterCustomBlur
  4.  
Use one of these function for the second bitmap, beforn you put it on the first.

Winni
Title: Re: BGRABitmap blur effect
Post by: circular on May 25, 2021, 06:27:20 pm
Note that it will allocate a new bitmap. You can use BGRAReplace for example.
Title: Re: BGRABitmap blur effect
Post by: pcurtis on May 25, 2021, 07:14:33 pm
I've tried this

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   MyBM : TBGRABitmap;
  4.   MyBD : TBGRABitmap;
  5.   MyDS : TBGRABitmap;
  6. begin
  7.  
  8.   with Image1 do
  9.     begin
  10.       Left := (Form1.Width div 2) - 550;
  11.       Top := (Form1.Height div 2) - 310;
  12.       Width := 1100;
  13.       Height := 619;
  14.       Center := False;
  15.       Stretch := True;
  16.     end;
  17.  
  18.  
  19.  
  20.   MyBM := TBGRABitmap.Create(1000, 1000, clBtnFace);
  21.  
  22.   MyDS := TBGRABitmap.Create(400, 400, clGrayText);
  23.   MyBD := MyDS.FilterBlurMotion(400, 45, True);
  24.   MyBM.PutImage(300, 300, MyBD, dmFastBlend);
  25.  
  26.   MyBM.SaveToFile('test.png');
  27.   MyBM.Free;
  28.   MyBD.Free;
  29.   MyDS.Free;
  30.  
  31.   Image1.Picture.LoadFromFile('test.png');
  32. end;
  33.  

and can't get it to work.
Title: Re: BGRABitmap blur effect
Post by: circular on May 25, 2021, 07:25:29 pm
Can you be more specific?
Title: Re: BGRABitmap blur effect
Post by: pcurtis on May 25, 2021, 07:48:03 pm
There is no shadow around the box.
Title: Re: BGRABitmap blur effect
Post by: circular on May 25, 2021, 09:48:04 pm
Ah ok.

It is because the image you blur is limited to this box. You need to have an image with a border of empty pixels of the same width as the blur effect.

Or you can simply use an image of the same size as the target image, paint the rectangle in at the desired position, and apply the blur effect to the image. Then put it at coordinate (0, 0) of the final image.
Title: Re: BGRABitmap blur effect
Post by: pcurtis on May 26, 2021, 12:32:44 am
Do you have a quick sample? Some code.
Say, blur 5 pixels around MyDS := TBGRABitmap.Create(400, 400, clGrayText);
Title: Re: BGRABitmap blur effect
Post by: circular on May 28, 2021, 06:40:16 pm
Code: Pascal  [Select][+][-]
  1.   MyDS := TBGRABitmap.Create(400+radius*2, 400+radius*2);
  2.   MyDS.FillRect(radius, radius, radius+400, radius+400, clGrayText);
  3.   MyBD := MyDS.FilterBlurRadial(radius);
  4.   MyBM.PutImage(300 - radius, 300 - radius, MyBD, dmFastBlend);
Title: Re: BGRABitmap blur effect
Post by: pcurtis on May 29, 2021, 12:25:06 am
Thanks
TinyPortal © 2005-2018