【发布时间】:2009-07-04 11:47:44
【问题描述】:
有没有办法可以将 WPF 的输出(例如画布)写入图像文件、jpg 等。
我想使用 WPF 为我创建背景,因为我想使用 矩形的 BitmapEffects 以及圆角的半径。
我想在网页中使用位图。
这可能吗?
马尔科姆
【问题讨论】:
标签: wpf
有没有办法可以将 WPF 的输出(例如画布)写入图像文件、jpg 等。
我想使用 WPF 为我创建背景,因为我想使用 矩形的 BitmapEffects 以及圆角的半径。
我想在网页中使用位图。
这可能吗?
马尔科姆
【问题讨论】:
标签: wpf
我有一篇关于此here 的博文。这是文章中的代码:
Rect rect = new Rect(canvas.RenderSize);
RenderTargetBitmap rtb = new RenderTargetBitmap((int)rect.Right,
(int)rect.Bottom, 96d, 96d, System.Windows.Media.PixelFormats.Default);
rtb.Render(canvas);
//encode as PNG
BitmapEncoder pngEncoder = new PngBitmapEncoder();
pngEncoder.Frames.Add(BitmapFrame.Create(rtb));
//save to memory stream
System.IO.MemoryStream ms = new System.IO.MemoryStream();
pngEncoder.Save(ms);
ms.Close();
System.IO.File.WriteAllBytes("logo.png", ms.ToArray());
Console.WriteLine("Done");
【讨论】: