【发布时间】:2014-09-14 02:57:15
【问题描述】:
我制作了一个 WPF 画布程序,它允许用户添加一些 PNG 模板并进行自己的新设计。
我可以完成工作
但是当我尝试保存时,我得到了白色背景 有什么办法可以得到透明的输出吗?
这是我保存图片的代码
public void SaveTo(string f)
{
Visual v = Dc;
/// get bound of the visual
Rect b = VisualTreeHelper.GetDescendantBounds(v);
/// new a RenderTargetBitmap with actual size of c
RenderTargetBitmap r = new RenderTargetBitmap(
(int)b.Width, (int)b.Height,
96, 96, PixelFormats.Pbgra32);
/// render visual
r.Render(v);
/// new a JpegBitmapEncoder and add r into it
JpegBitmapEncoder e = new JpegBitmapEncoder();
e.Frames.Add(BitmapFrame.Create(r));
/// new a FileStream to write the image file
FileStream s = new FileStream(f,
FileMode.OpenOrCreate, FileAccess.Write);
e.Save(s);
s.Close();
}
【问题讨论】:
-
你知道在变量名中使用多个字母是完全合法的 :)