2010-06-03 160 views
0

我的项目我想使用EmguCV库,但EmguCV的功能无法处理Bitmap对象,所以我必须将Bitmap转换为其他类型,Intptr是一个选择,但我真不知道如何编码,老乡代码是抽象的,从我的项目是这样的:如何将位图转换为intptr C#

Bitmap bmp = new Bitmap(e.width, e.height, 
    System.Drawing.Imaging.PixelFormat.Format24bppRgb); 
System.Drawing.Imaging.BitmapData data = 
    bmp.LockBits(new Rectangle(0, 0, e.width, e.height), 
     System.Drawing.Imaging.ImageLockMode.ReadWrite, 
     System.Drawing.Imaging.PixelFormat.Format24bppRgb); 
int dataLength = e.width * e.height * 3; 
Win32.memcpy(data.Scan0, (IntPtr)e.data, (uint)dataLength); 
convertBitmapToIntptr(bmp); 

我怎么能在这个功能convertBitmapToIntptr(bmp)代码?

+0

不太确定你在问什么? – 2010-06-03 01:19:02

+0

你在寻找GetHbitmap()吗? http://msdn.microsoft.com/en-us/library/1dz311e4.aspx – 2010-06-03 13:40:31

回答

0

你想在一个类来包装这个....

我已经做到了这一点,并把它称为“FastBitmap”,你可以在构造函数中锁定,获得了PTR,并添加方法一起工作在PTR

1

这可能是一个老问题,但如果你正在使用EmguCV,位图转换的IntPtr可以做(为2.4.2版本),如下面的例子:

Bitmap bitmap = new Bitmap("pathToBitmapFile"); 

Image<Bgr,byte> image = new Image<Bgr,byte>(bitmap); 

IntPtr = image.Ptr; 

EmguCV Documentation