保存应用了着色器效果的 WPF 图像 [英] Save WPF image with Shader effects applied

查看:29
本文介绍了保存应用了着色器效果的 WPF 图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有模糊效果的 WPF 图像控件.有没有办法在不使用 RenderTargetBitmap 的情况下保存图像(带有模糊)?

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

谢谢.

更新:我现在使用派生自 System.Windows.Media.Effects.ShaderEffect 的新自定义效果.我想保存应用了着色器效果的图像.

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.

推荐答案

渲染位图的唯一方法是使用 RenderTargetBitmap.

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

看看这个例子:

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

希望能帮到你

这篇关于保存应用了着色器效果的 WPF 图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆