tags:

views:

516

answers:

1
+1  Q: 

Draw drop shadow

Hi!

I want to add a drop shadow to an image file. What's the best way to do that? I thought about creating a WPF Image control and adding a bitmap effect.. But how can I save the result to a file?

Thanks, Eric

+1  A: 

You can use RenderTargetBitmap and an Enocder to do this. Encoder can be Png,Jpeg etc.. Below code imgControl represents your Image control. But since it is a bitmap effect you might need to put this Image inside a grid and give proper margin equivalent to the dropshadow and then instead of imgControl use the grid in the below code.

        double Height = imgControl.ActualHeight;
        double Width = imgControl.ActualWidth;

        RenderTargetBitmap bmp = new RenderTargetBitmap((int)Width, (int)Height, 96, 96, PixelFormats.Pbgra32);
        bmp.Render(imgControl);

        BitmapEncoder encoder = new JpegBitmapEncoder();

        encoder.Frames.Add(BitmapFrame.Create(bmp));

        using (Stream stream = File.Create("Yourfile.jpeg"))
        {
            encoder.Save(stream);
        }
Jobi Joy
thanks so much !! :)
eWolf