标签:
using System.Windows.Media.Imaging; using System.IO; private void SaveToImage(FrameworkElement ui, string fileName, int width, int height) { try { System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Create); RenderTargetBitmap bmp = new RenderTargetBitmap(width, height, 96d, 96d, PixelFormats.Pbgra32); bmp.Render(ui); BitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(bmp)); encoder.Save(fs); fs.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
标签:
原文地址:http://www.cnblogs.com/sunqiliang/p/5386552.html