Cant get Image Drop Shadow to Work

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Post Reply
coderanger
Posts: 2
Joined: 2017-03-21T15:05:47-07:00
Authentication code: 1151

Cant get Image Drop Shadow to Work

Post by coderanger »

I am having a really hard time trying to get drop shadows for an image to work; i thought it would be quite easy but no matter what i do nothing works.

This is the code i am trying to use with the following image Image

Code: Select all

using( MagickImage image = new MagickImage( "d:\\mainimage.jpg" ) )
using( var savedShadowImageStream = new FileStream( "d:\\shadow-imagemagik.jpg", FileMode.Create ) )
{
    image.Strip();
    image.Quality = 100;
    image.Resize( 2000, 0 );

    MagickImage shadow = image.Clone();
    shadow.Quality = 100;

    // shadow( x, y, sigma, alpha, colour )
    // basically i dont get any sort of blurred shadow
    // x and y dont seem to do anything at all
    // sigma seems to be shadow size and not the amount of blur
    // alpha doesnt seem to do anything either
    shadow.Shadow( 10, 10, 0.5, new Percentage( 80 ), MagickColor.FromRgb( 127, 127, 127 ) ); // this makes the shadow size tiny
//    shadow.Shadow( 10, 10, 20, new Percentage( 80 ), MagickColor.FromRgb( 127, 127, 127 ) ); // this makes the shadow size bigger, but why its supposed to be the blur size

    shadow.Composite( image, CompositeOperator.Replace );

    shadow.Write( savedShadowImageStream, MagickFormat.Jpeg );
}
I even tried an example posted in these forums and that didnt work either, all I get is the following look: Image

When what i want is:
Image

Can anyone help please; i have spent all day on this and am not really any further forward.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Cant get Image Drop Shadow to Work

Post by snibgo »

Why are you writing to JPEG? That format removes transparency, so you can't see the effect of the shadow.

While you are developing, I suggest you should write to a format that has transparency, and doesn't mangle the pixels, such as PNG.

As a further clue, your "desired output" has clearly been flattened against a white background. I don't see that step in your code.
snibgo's IM pages: im.snibgo.com
coderanger
Posts: 2
Joined: 2017-03-21T15:05:47-07:00
Authentication code: 1151

Re: Cant get Image Drop Shadow to Work

Post by coderanger »

Of course; good point!! Thanks
Post Reply