Recent

Author Topic: [SOLVED] BGRABitmap blur effect  (Read 4330 times)

pcurtis

  • Hero Member
  • *****
  • Posts: 637
[SOLVED] BGRABitmap blur effect
« 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)
« Last Edit: May 29, 2021, 12:25:55 am by pcurtis »
Windows 10
Laz 2.0.10
FPC 3.2.0

winni

  • Hero Member
  • *****
  • Posts: 2670
Re: BGRABitmap blur effect
« Reply #1 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

circular

  • Hero Member
  • *****
  • Posts: 3722
    • Personal webpage
Re: BGRABitmap blur effect
« Reply #2 on: May 25, 2021, 06:27:20 pm »
Note that it will allocate a new bitmap. You can use BGRAReplace for example.
Conscience is the debugger of the mind

pcurtis

  • Hero Member
  • *****
  • Posts: 637
Re: BGRABitmap blur effect
« Reply #3 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.
Windows 10
Laz 2.0.10
FPC 3.2.0

circular

  • Hero Member
  • *****
  • Posts: 3722
    • Personal webpage
Re: BGRABitmap blur effect
« Reply #4 on: May 25, 2021, 07:25:29 pm »
Can you be more specific?
Conscience is the debugger of the mind

pcurtis

  • Hero Member
  • *****
  • Posts: 637
Re: BGRABitmap blur effect
« Reply #5 on: May 25, 2021, 07:48:03 pm »
There is no shadow around the box.
Windows 10
Laz 2.0.10
FPC 3.2.0

circular

  • Hero Member
  • *****
  • Posts: 3722
    • Personal webpage
Re: BGRABitmap blur effect
« Reply #6 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.
Conscience is the debugger of the mind

pcurtis

  • Hero Member
  • *****
  • Posts: 637
Re: BGRABitmap blur effect
« Reply #7 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);
« Last Edit: May 26, 2021, 12:54:41 am by pcurtis »
Windows 10
Laz 2.0.10
FPC 3.2.0

circular

  • Hero Member
  • *****
  • Posts: 3722
    • Personal webpage
Re: BGRABitmap blur effect
« Reply #8 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);
Conscience is the debugger of the mind

pcurtis

  • Hero Member
  • *****
  • Posts: 637
Re: BGRABitmap blur effect
« Reply #9 on: May 29, 2021, 12:25:06 am »
Thanks
Windows 10
Laz 2.0.10
FPC 3.2.0

 

TinyPortal © 2005-2018