我正在尝试将 wpf 控件保存到文件,但我正在对其应用 PixelShader 效果,当我尝试保存时,保存的图像完全是白色、黑色或红色......取决于效果的参数.
我在这里使用代码:WPF - BitmapEffect 上的编程绑定
我怎样才能正确保存它?
谢谢!
更新:我使用的代码是:
BitmapSource bitmap = preview.Source as BitmapImage;
Rectangle r = new Rectangle();
r.Fill = new ImageBrush(bitmap);
r.Effect = effect;
Size sz = new Size(bitmap.PixelWidth, bitmap.PixelHeight);
r.Measure(sz);
r.Arrange(new Rect(sz));
var rtb = new RenderTargetBitmap(bitmap.PixelWidth, bitmap.PixelHeight, bitmap.DpiX, bitmap.DpiY, PixelFormats.Pbgra32);
rtb.Render(r);
PngBitmapEncoder png = new PngBitmapEncoder();
png.Frames.Add(BitmapFrame.Create(rtb));
Stream stm = File.Create("new.png");
png.Save(stm);
stm.Close();