c# - 如何在C#中将位图转换为intptr

在我的项目中,我想使用EmguCV lib,但是EmguCV的功能无法处理Bitmap对象,因此我必须将Bitmap转换为其他类型,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)中进行编码?

最佳答案

这可能是一个古老的问题,但是如果您使用的是EmguCV,则可以完成位图到IntPtr的转换(从2.4.2版开始),如下例所示:

Bitmap bitmap = new Bitmap("pathToBitmapFile");

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

IntPtr = image.Ptr;   

参见EmguCV Documentation

https://stackoverflow.com/questions/2962747/

相关文章:

visual-c++ - Visual c++ OpenCV 2.1 contains()

image - OpenCV模板匹配

user-interface - 在Win32应用程序中使用opencv进行图像显示

docker - 创建 Docker 自己的 node_modules

visual-studio-2008 - OpenCV图像从RGB转换为HSV阈值难题

docker - TeamCity 构建代理 : Error registering on the

visual-studio-2008 - CBlobResult令人费解。使用Visual C++2

opencv - 模拟相机的进纸

visual-c++ - 使用卷积方法处理35 x 35内核

opencv - 相机和投影仪校准