首页 > Windows开发 > 详细

WPF 实现指定UI控件截图

时间:2016-04-13 12:52:52      阅读:287      评论:0      收藏:0      [点我收藏+]
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);
            }
        }

WPF 实现指定UI控件截图

原文:http://www.cnblogs.com/sunqiliang/p/5386552.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!