Passing bitmap from c# to c++

后端 未结 4 998
后悔当初
后悔当初 2020-12-15 00:59

I have an image processing function written in C++ based on opencv. In my wpf application I have used AForge library to access a webcam and update it on UI. This the functio

4条回答
  •  有刺的猬
    2020-12-15 01:54

    Depends on the scope. If you can guarantee the bitmap isn't used elsewhere, you can lock the image buffer, and then pass the pointer down to the C++ code, and unlock it afterwards.

    The LockBits command returns a BitmapData class that has a pointer to the image buffer in its Scan0 property:

    BitmapData bmpData = bitmapFrame.LockBits(new Rectangle(0, 0, bitmapFrame.Width, bitmapFrame.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, 
                System.Drawing.Imaging.PixelFormat.Format24bppRgb);
    
    NativeFunctions.FaceTracker(bmpData.Scan0 , bitmapFrame.Width, bitmapFrame.Height);
    
    bitmapFrame.UnlockBits(bmpData); //Remember to unlock!!!
    

提交回复
热议问题