2013-05-10 99 views
0

我用TWAIN_32的掃描和twainLib.TransferPictures使用DibToBitmap.FormHDib(hbitmap)擺脫IntPtr一個bitmapsource,但我希望有一個bitmapimage轉換的IntPtr到BitmapImage的

我要轉換的IntPtrbitmapsourcebitmapimage,而不是直接使之成爲bitmapsource然後bitmapimage

回答

0

使用Bitmap Constructor Method

Bitmap newBitmap = new Bitmap(width, height, Stride, PixelFormat, bitmapSource); 
+0

這將是一個位圖不是位圖圖像 – Akrem 2013-05-10 09:02:56

+1

位圖實際上是一個位圖圖像,因爲它繼承了圖像類。一旦你有了位圖,你可以使用像[save](http://msdn.microsoft.com/en-us/library/ktx83wah.aspx)這樣的圖像來做任何事情,將它設置爲圖片框/圖像對象等。 – 2013-05-10 09:10:28

0

既然你問BitmapSource和你的問題是標籤與WPF ,這裏有一種避免使用的方法:System.Drawing.Bitmap

Imaging.CreateBitmapSourceFromHBitmap(imagePointer, IntPtr.Zero, Int32Rect.Empty, 
    BitmapSizeOptions.FromEmptyOptions()); 

您需要使用System.Windows.Interop