Drop Shadows

I’ve seen the question come up many times over the years, and I think I finally have a pretty fast native solution that looks very nice.

This code could use some nil checking and could be modified to allow offsets etc, but here it is. (looks best to me at radius=50)

I might change it to “walk back” from the right and bottom edges to avoid artifacts, but I think it’s pretty good as is.


[code]Private Function AddShadow(p As Picture,radius As integer) As Picture
dim pic As new Picture(p.Width+radius,p.Height+radius)

dim pg As Graphics=pic.Graphics

for x as integer=0 to p.width step 4
for y as integer=0 to p.height step 4
if xp.width-radius or yp.height-radius then pg.fillOval x,y,radius,radius
pg.ClearRect (pg.Width-p.width)/2,radius/3,p.width,p.height
pg.DrawPicture p,(pg.Width-p.width)/2,radius/3

Return pic
End Function

Very nice ! I tried changing the color of the shadow, and it works too. And since it is pure Xojo, it works fine cross platform.

Thank you Jim.

No Problem!

You can also use the rgbSurface of the source picture to change the color of each oval and get a cool translucent effect. (and it’s not insanely slow)

Using step 2 in the for loops looks better for smaller radius too. (but much slower)