码迷,mamicode.com
首页 > Windows程序 > 详细

WPF:How to display a Bitmap on Image control

时间:2017-07-18 19:41:46      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:bit   splay   wpf   end   解决   删除   无法   absolute   bug   

一个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

标签:bit   splay   wpf   end   解决   删除   无法   absolute   bug   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!