首页 > Windows开发 > 详细

WPF:How to display a Bitmap on Image control

时间:2017-07-18 19:23:55      阅读:247      评论:0      收藏:0      [点我收藏+]

一个Bitmap文件,叫做screenShotFile, 你可以这样显示到Image控件上。

            BitmapImage bi = new BitmapImage();
            bi.BeginInit();
            bi.UriSource = new Uri(this.screenShotFile, UriKind.Absolute);
            bi.EndInit();
            this.screenshotImage.Source = bi;

但是有个问题,这个文件你无法删除,会报错说“另一个进程正在使用”。什么鬼?是bug吗?

 

如果你的Bitmap还在内存里,这个问题就比较好解决了:

            BitmapSource bs = Imaging.CreateBitmapSourceFromHBitmap(this.bmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(bmp.Width, bmp.Height));
            this.screenshotImage.Source = bs;

其中,Imaging的namespace是这个:namespace System.Windows.Interop

 

WPF:How to display a Bitmap on Image control

原文:http://www.cnblogs.com/ms-uap/p/7202206.html

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