【问题标题】:Write WPF output to image file将 WPF 输出写入图像文件
【发布时间】:2009-07-04 11:47:44
【问题描述】:

有没有办法可以将 WPF 的输出(例如画布)写入图像文件、jpg 等。

我想使用 WPF 为我创建背景,因为我想使用 矩形的 BitmapEffects 以及圆角的半径。

我想在网页中使用位图。

这可能吗?

马尔科姆

【问题讨论】:

    标签: wpf


    【解决方案1】:

    我有一篇关于此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");
    

    【讨论】:

      猜你喜欢
      • 2011-12-06
      • 1970-01-01
      • 2013-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多