一個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
?