I am looking for some good way to make convincing shadows.
I know you’ll have to take the Mask and blur and lighten it, then use it as the mask of a solid-black picture, which you draw with the desired offset.
Blurring seems to be difficult to do.
I know it can be done with CG but I need a cross platform way.
[quote=79368:@Christoph De Vocht]I am looking for some good way to make convincing shadows.
I know you’ll have to take the Mask and blur and lighten it, then use it as the mask of a solid-black picture, which you draw with the desired offset.
Blurring seems to be difficult to do.
I know it can be done with CG but I need a cross platform way.
Anyone has luck with this?[/quote]
Could you use the ImagePlayEffects library for blurring? From what I can remember, it slow but it works. http://sourceforge.net/projects/imageplay/
I’ve been messing around with a blur method… it essentially creates a matrix of scaled down images from the original and then creates a new image by iterating through the matrix pixel by pixel. Works pretty well, but get a little funky above a 30x30 matrix… but I think that depends on the size of the original too… see what you think. (might be a little hard to decipher, just ask if you need clarification…)
[code]Private Function scalePicByMatrix(p As Picture,MatrixSize As integer) As Picture #Pragma DisableBoundsChecking #pragma NilObjectChecking false #Pragma DisableBackgroundTasks
dim workpic As new Picture(p.width+MatrixSize4,p.height+MatrixSize4)
dim buffers as new Picture(workpic.Width+MatrixSize-(workpic.Width mod MatrixSize),workpic.Height+MatrixSize-(workpic.Height mod MatrixSize))
dim buffergraphics As Graphics=buffers.Graphics
dim res As new Picture(workpic.Width,workpic.Height)
dim xmult As double=buffers.width/MatrixSize
dim ymult As double=buffers.height/MatrixSize
workpic.graphics.drawpicture p,MatrixSize2,MatrixSize2
for x as integer=0 to MatrixSize-1
for y as integer=0 to MatrixSize-1
buffergraphics.DrawPicture(workpic,(xmultx),(ymulty),xmult,ymult,x,y,workpic.Width-MatrixSize,workpic.Height-MatrixSize)
next
next
dim surfaces as RGBSurface=buffers.RGBSurface
dim s As RGBSurface=res.RGBSurface
for x as integer=0 to res.Width-1
for y as integer=0 to res.Height-1
s.Pixel(x,y)=surfaces.pixel( (x/MatrixSize)+(xmult*(x mod MatrixSize)) , (y/MatrixSize)+(ymult*(y mod MatrixSize) ))
next
next
workpic=new Picture(p.width,p.height)
workpic.graphics.drawpicture res,0,0,p.width,p.height,MatrixSize2,MatrixSize2
Return workpic
End Function
[/code]
Here’s a companion to the code I posted above.
This will draw an image with a dropshadow to a graphics object. Keep in mind that blur>10 will be sloooow.
(the above method was called scaleByMatrix. You’ll need to change it to BlurByMatrix)
[code]Private Sub DrawWithShadow(g As Graphics,p As Picture,picx As integer,picy As integer, shadXoff As integer,shadYoff as integer, blur As integer, fill as color=&c00000000)
dim m As new picture(p.Width,p.Height)
dim shadow As new picture(p.Width,p.Height,32)
I must admit, with my budget I have not YET bought the MBS plugins but I have tried it out a little and it is really cool because it is massively powerful because it has such a wide-range of functions for just about anything you would expect from a library of this sort. The developer of it might add new things to the plugin on high enough request. He is a nice guy.
http://einhugur.com/Html/Libs.html Björn’s Picture Effects plugin is x-plat and has some really highly optimized effects. I think version 9.0.2 is the latest.