Save WPF Image with Shader Effects Applied

I have a WPF Image control with a blur effect attached. Is there a way to save an image (with blur) without using a RenderTargetBitmap?

Thanks.

UPDATE: I now use a new custom effect that comes from System.Windows.Media.Effects.ShaderEffect. I would like to save my image with the applied shader effect.

+4
source share
5 answers

the only way to render a bitmap is to use a RenderTargetBitmap.

Take a look at this example:

BitmapSource bitmap=GetYourBitmap(); Rectangle r=new Rectangle(); r.Background=new ImageBrush(bitmap); r.Effect=yourEffect; Size sz=new Size(bitmap.PixelWidth, bitmap.PixelHeight); r.Measure(sz); r.Arrange(new Rect(sz); var rtb=new RenderTargetBitmap(); rtb.Render(r); return rtb;//here is your bitmap with effects applied 

Hope this helps

+7
source

I know this is an old question ... but I thought I would point people to a message from Jamie Rodriguez ( http://blogs.msdn.com/jaimer/archive/2009/07/03/rendertargetbitmap-tips.aspx ) to this thing.

I had a situation where using RenderTargetBitmap resulted in a blank image ... and Jamie's message was the answer for me.

Hope this helps someone else too.

+2
source

This is what I also wanted. According to this: http://social.msdn.microsoft.com/Forums/en/wpfprerelease/thread/e2ebf264-e087-4bfe-a69b-24c884675c80 RenderTargetBitmap does not use HW (GPU) for rendering, only for software. What a pity.

HF

+2
source

Since the shader effect is by definition applied to the video card, the only way to get a copy of it in the main memory is to capture it from the screen memory. So RenderTargetBitmap is your solution. Is there any specific reason why you wanted to avoid it?

+1
source

Here you will find: http://perspectivefx.codeplex.com/ and all the work done using the GPU

0
source

All Articles