Recent

Author Topic: Blur BGRAShape?  (Read 4452 times)

dietmar

  • Full Member
  • ***
  • Posts: 170
Blur BGRAShape?
« on: August 19, 2021, 07:18:33 pm »
Hi,

does anyone has a code example on how to blur a bgrashape?

Thx,
--Dietmar
Lazarus 2.2.0RC1 with FPC 3.2.2 (32 Bit) on Windows10 (64Bit)

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Blur BGRAShape?
« Reply #1 on: August 20, 2021, 12:25:39 am »
Hi!

There are a lot of filters to blur a TBGRAbitmap, BUT

The TBGRAShape contains only a TBGRAbitmap in the private section.
So you have to create a derived class from the TBGRAShape where the TBGRAbitmap is public.

The TBRAbitmap has it's own board in this forum:

https://forum.lazarus.freepascal.org/index.php/board,46.0.html

It is better tp place your questions about TBGRA there.

Winni

dietmar

  • Full Member
  • ***
  • Posts: 170
Re: Blur BGRAShape?
« Reply #2 on: August 20, 2021, 09:55:39 pm »
Hi,

ok, so here we are... has anybody a little bit of code for me? ;)

--Dietmar
Lazarus 2.2.0RC1 with FPC 3.2.2 (32 Bit) on Windows10 (64Bit)

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Blur BGRAShape?
« Reply #3 on: August 21, 2021, 02:20:53 pm »
Hi!

There is no easy way to blur a BGRAshape.

But you can use a workaround:

Replace the BGRAshape with a TShape.

Copy the canvas to a BGRAbitmap.
Blur the BGRAbitmap
Copy it back to the canvas:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var bmp : TBGRABitmap;
  3.     R : TRect;
  4. begin
  5.  bmp := TBGRAbitmap.Create (Shape1.Width,Shape1.height);
  6.  R := rect(0,0,Shape1.Width,Shape1.height);
  7.  bmp.Canvas.CopyRect(R,Shape1.Canvas, R);
  8. // draw a circle for test
  9.   bmp.EllipseAntialias(Shape1.Width / 2 ,Shape1.height/2,15,15,cssBlack,2,cssRed);
  10.  BGRAReplace (bmp,bmp.FilterBlurMotion(8,180,true));
  11.  bmp.Draw(Shape1.Canvas,0,0);
  12.  bmp.free;
  13. end;                  
  14.  
  15.  

Winni

dietmar

  • Full Member
  • ***
  • Posts: 170
Re: Blur BGRAShape?
« Reply #4 on: August 22, 2021, 03:20:20 pm »
Cool, thank you ;)

--Dietmar
Lazarus 2.2.0RC1 with FPC 3.2.2 (32 Bit) on Windows10 (64Bit)

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Blur BGRAShape?
« Reply #5 on: August 23, 2021, 05:59:24 pm »
Hi!

If you insist on TBGRAshape and don't want to fiddle with the TBGRAShape class then I have only one rude solution for you:

Take a partial screenshot and draw it on the Form.canvas - over the BGRAshape.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var bmp : TBGRABitmap;
  3.     R : TRect;
  4.     TopL, BottomR : TPoint;
  5. begin
  6. TopL :=ClientToScreen(Point(BGRAShape1.left, BGRAShape1.top ));
  7. BottomR := ClientToScreen(Point(BGRAShape1.left + BGRAShape1.width,
  8.                                 BGRAShape1.top+ BGRAShape1.Height) );
  9.  
  10. R := Rect(TopL.X,TopL.Y,   BottomR.X, BottomR.y);
  11. bmp := TBGRABitmap.create;
  12. bmp.TakeScreenshot(R);
  13. bmp.EllipseAntialias(BGRAShape1.Width / 2 ,BGRAShape1.height/2,15,15,cssBlack,2,cssRed);
  14. BGRAReplace (bmp,bmp.FilterBlurMotion(8,180,true));
  15. bmp.draw(canvas,BGRAshape1.left, BGRAshape1.top);
  16. bmp.free;
  17. end;

But both shown solutions are not satisfying.

TBGRAShape should be enhanced:

Either with a public TBGRAbitmap.

Or with  a public Canvas and a published onPaint event.

Winni

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: Blur BGRAShape?
« Reply #6 on: September 02, 2021, 09:42:47 pm »
Hmm well there are things to consider. The blur would be limited to the rectangle area of the control. Though you might want to go further. It could be a shadow, but still draw the shape over it, etc.

Another solution is to put a TBGRAGraphicControl and draw exactly what you wants.

Another solution would be to create your own control but duplicating the existing one, changing its name and changing how it renders.
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018