开发者

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, 开发者_Python百科(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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜