wpf 将 IntPtr 转换为位图图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16478449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
convert IntPtr to bitmapimage
提问by Akrem
I use twain_32 for the scan and in twainLib.TransferPicturesuse DibToBitmap.FormHDib(hbitmap)to get a bitmapsourcefrom IntPtrbut I want a bitmapimage.
我用TWAIN_32的扫描和 twainLib.TransferPictures使用DibToBitmap.FormHDib(hbitmap)得到一个bitmapsource从IntPtr,但我想要一个bitmapimage。
I want to convert the IntPtrbitmapsourceto bitmapimagedirectly instead to make it a bitmapsourcethen a bitmapimage
我想将转换IntPtrbitmapsource到bitmapimage直接,而不是使之成为bitmapsource再bitmapimage
采纳答案by Chibueze Opata
Use the Bitmap Constructor Method
使用位图构造方法
Bitmap newBitmap = new Bitmap(width, height, Stride, PixelFormat, bitmapSource);
回答by Nicke Manarin
Since you are asking about BitmapSourceand your question is tagged with WPF, here's a way to avoid using System.Drawing.Bitmap:
由于您正在询问BitmapSource并且您的问题带有 标记WPF,因此有一种避免使用的方法System.Drawing.Bitmap:
Imaging.CreateBitmapSourceFromHBitmap(imagePointer, IntPtr.Zero, Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
You'll need to use System.Windows.Interop.
你需要使用System.Windows.Interop.

