Recent

Author Topic: Drop shadow using BGRABitmap  (Read 6505 times)

Dibo

  • Hero Member
  • *****
  • Posts: 1057
Drop shadow using BGRABitmap
« on: December 02, 2012, 07:10:04 pm »
Hi,

I have some button drawed on TBGRABitmap, how I can drop smoth shadow? I have idea: create copy of bitmap, convert to grayscale and apply blur effect, but maybe there is faster way?

Regards

Edit: This is my current code which is working fine, but maybe it could be more optimized (without duplicating grayscale):
Code: [Select]
shadow := TBGRABitmap(FilterGrayscale(b));
BGRAReplace(shadow, shadow.FilterBlurRadial(1, rbFast));
« Last Edit: December 02, 2012, 07:32:52 pm by Dibo »

circular

  • Hero Member
  • *****
  • Posts: 4471
    • Personal webpage
Re: Drop shadow using BGRABitmap
« Reply #1 on: December 02, 2012, 08:01:15 pm »
Unfortunately, BGRABitmap does not work with grayscale images yet.

Something I can see is that it maybe that only a small portion of the image contains something. Is it the case ? (for example a 800x600 image with 50x50 object to be shadowed)

In this case, it would be useful to use GetImageBounds and apply on a smaller portion.
Conscience is the debugger of the mind

lainz

  • Guest
Re: Drop shadow using BGRABitmap
« Reply #2 on: December 02, 2012, 09:50:20 pm »
If the button has transparency you need the whole shadow, just remember that.

Dibo

  • Hero Member
  • *****
  • Posts: 1057
Re: Drop shadow using BGRABitmap
« Reply #3 on: December 03, 2012, 03:10:47 pm »
What I mean is create shadow around buttons borders (similar like TSpeedButton or TButton has, see attached screen)

lainz

  • Guest
Re: Drop shadow using BGRABitmap
« Reply #4 on: December 03, 2012, 05:08:23 pm »
And you can show me the button you're drawing? If isn't very complex you can try to use slice scaling, at least to create the shadow.

Dibo

  • Hero Member
  • *****
  • Posts: 1057
Re: Drop shadow using BGRABitmap
« Reply #5 on: December 03, 2012, 06:30:05 pm »
I attached screen with my button, first has little shadow, second doesn't. I got it with :

  shadow := TBGRABitmap(FilterGrayscale(b));
  BGRAReplace(shadow, shadow.FilterBlurRadial(1, rbFast));

  // Drawing on canvas
  b.PutImage(0,0,shadow,dmDrawWithTransparency);

And looks fine, but I thought that maybe there is faster way to drop shadow

lainz

  • Guest
Re: Drop shadow using BGRABitmap
« Reply #6 on: December 03, 2012, 08:34:30 pm »
Looks nice, well no idea how to create a faster shadow..

BTW that is a 1px shadow isn't it? So instead of bluring just draw an antialiased rounded shape with alpha first and then draw the button.

With BGRASliceScaling the settings I've used for the image you provided are those:

Margins: 5, 5, 5, 5.
Repeat: Horizontal, Top, Bottom, Left, Right.

The min size of the bitmap can be 11x11 with 1 pixel for the fill (white)...

BTW You're using a vertical gradient: maybe you want to keep the current image height, and reduce the width to 11.

circular

  • Hero Member
  • *****
  • Posts: 4471
    • Personal webpage
Re: Drop shadow using BGRABitmap
« Reply #7 on: December 05, 2012, 10:11:44 am »
BTW that is a 1px shadow isn't it? So instead of bluring just draw an antialiased rounded shape with alpha first and then draw the button.
I was thinking something similar. If a simple rounded shape is not blurred enough, well, you can draw two antialiased rounded shapes with :
Code: [Select]
b.RoundRectAntialias(x,y,x2,y2,rx,ry: single; pencolor: TBGRAPixel; w: single; fillcolor: TBGRAPixel; options: TRoundRectangleOptions = []);where you define for example pencolor = BGRA(0,0,0,32), w = 1, fillcolor = BGRA(0,0,0,48)
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018