如何在C#中将IntPtr转换为Image [英] how to convert IntPtr to Image in C#
本文介绍了如何在C#中将IntPtr转换为Image的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello Everyone。
i希望将
Hello Everyone.
i want to convert
IntPtr
转换为
Image
。
i试试这个。但没有给我一张扫描图片。
.
i have try this. but not given me a scan image.
IntPtr img = (IntPtr) pics[ i ];
Bitmap _img = new Bitmap(2450, 2450, 2452, PixelFormat.Format32bppRgb, img)
pictureBox1.Image = _img;
推荐答案
在这里谈论转换是不正确的;更重要的是,我们不知道什么是pics
。最有可能的是,输入IntPtr
是不切实际的荒谬;此类型用于将指针传递给非托管内存或对象句柄。
但实质上,我可以想象你有一些数据结构描述颜色(或颜色+ alpha)对于每个像素,您需要将此数据放在位图中。然后答案非常明显: https:/ /msdn.microsoft.com/en-us/library/system.drawing.bitmap.lockbits%28v=vs.110%29.aspx [ ^ ]。
您可以在MSDN帮助页面上找到有关这些类似方法之一的完整代码示例。
-SA
Talking about "conversion" here is incorrect; and, more importantly, we don't know what ispics
. Most likely, type casting toIntPtr
would be impractical absurd; this type is used for passing pointers to unmanaged memory or object handles.
But in essence, I can imagine that you have some data structures describing the color (or color+alpha) for each pixel, and you need to put this data in a bitmap. Then the answer is pretty obvious: https://msdn.microsoft.com/en-us/library/system.drawing.bitmap.lockbits%28v=vs.110%29.aspx[^].
You will find a complete code sample on the MSDN help page on one of these similar methods.
—SA
System.Drawing.Image.FromHbitmap(IntPtr输入)
System.Drawing.Image.FromHbitmap(IntPtr input)
这篇关于如何在C#中将IntPtr转换为Image的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文