C# 如何在C语言中将位图转换为intptr#
在我的项目中,我想使用EmguCV lib,但EmguCV的函数无法处理位图对象,因此我必须将位图转换为其他类型,Intptr是一种选择,但我真的不知道如何编码,其他代码是从我的项目中抽象出来的,如下所示:C# 如何在C语言中将位图转换为intptr#,c#,opencv,emgucv,C#,Opencv,Emgucv,在我的项目中,我想使用EmguCV lib,但EmguCV的函数无法处理位图对象,因此我必须将位图转换为其他类型,Intptr是一种选择,但我真的不知道如何编码,其他代码是从我的项目中抽象出来的,如下所示: Bitmap bmp = new Bitmap(e.width, e.height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); System.Drawing.Imaging.BitmapData data = b
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)
?您想将其包装在类中
我已经这样做了,并将其称为“FastBitmap”,您可以将其锁定在构造函数中,获取ptr,并添加方法来使用ptr这可能是一个老问题,但如果您使用的是EmguCV,则可以进行位图到IntPtr的转换(从版本2.4.2开始),如以下示例所示:
Bitmap bitmap = new Bitmap("pathToBitmapFile");
Image<Bgr,byte> image = new Image<Bgr,byte>(bitmap);
IntPtr = image.Ptr;
Bitmap Bitmap=新位图(“pathToBitmapFile”);
图像=新图像(位图);
IntPtr=image.Ptr;
请参见不太确定您要问什么?是否正在查找GetHbitmap()?