Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在C语言中将位图转换为intptr#_C#_Opencv_Emgucv - Fatal编程技术网

C# 如何在C语言中将位图转换为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

在我的项目中,我想使用EmguCV lib,但EmguCV的函数无法处理位图对象,因此我必须将位图转换为其他类型,Intptr是一种选择,但我真的不知道如何编码,其他代码是从我的项目中抽象出来的,如下所示:

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()?