简体   繁体   中英

how to convert bitmap to intptr in C#

in my project I want to use EmguCV lib, but the function of EmguCV can not process the Bitmap object, so i have to convert Bitmap to some other type, Intptr is a choice but I really don't know how to code, the fellow code is abstract from my project like this:

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);

How can I code in this function convertBitmapToIntptr(bmp) ?

This may be an old question but if you are using EmguCV, Bitmap to IntPtr conversion can be done (as of version 2.4.2) like the following example:

Bitmap bitmap = new Bitmap("pathToBitmapFile");

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

IntPtr = image.Ptr;   

See EmguCV Documentation

you want to wrap this in a class....

I've done this and called it "FastBitmap" and you can lock it in the constructor, get the ptr, and add methods to work with the ptr

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM