Save WPF image with Shader effects applied

2019-03-14 07:51发布

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

Thank you.

UPDATE: I'm using now new custom effect which derives from System.Windows.Media.Effects.ShaderEffect. I would like to save my image with shader effect applied.

标签: wpf imaging
5条回答
Rolldiameter
2楼-- · 2019-03-14 08:24

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

KV

查看更多
Summer. ? 凉城
3楼-- · 2019-03-14 08:33

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

查看更多
Ridiculous、
4楼-- · 2019-03-14 08:43

the only way you can render the bitmap is using RenderTargetBitmap.

Have 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

查看更多
爷的心禁止访问
5楼-- · 2019-03-14 08:44

I know this is an old question ... but I thought I would point people to Jamie Rodriguez's post (http://blogs.msdn.com/jaimer/archive/2009/07/03/rendertargetbitmap-tips.aspx) on this subject.

I had a situation where using RenderTargetBitmap was resulting in an empty image ... and Jamie's post was the answer for me.

Hope it helps someone else too.

查看更多
干净又极端
6楼-- · 2019-03-14 08:44

Here you go: http://perspectivefx.codeplex.com/ and all work done by GPU

查看更多
登录 后发表回答