//Method to get a c# Bitmap from a native C++ image pointer //DONT USE, HARDCODED! public static Bitmap getBitmapFromRGBImage(IntPtr image) { Console.WriteLine("pointer c#: " + image); int width = VisionDLL.imageWidth(image); int height = VisionDLL.imageHeight(image); Console.WriteLine("width: " + width); Console.WriteLine("Height: " + height); Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb); unsafe { BitmapData data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); IntPtr ptr = data.Scan0; Console.WriteLine("stride: " + data.Stride); int bytes = Math.Abs(data.Stride) * bitmap.Height; Console.WriteLine("bytes: " + bytes); byte[] rgbValues = new byte[bytes]; // Copy the RGB values into the array. Marshal.Copy(ptr, rgbValues, 0, bytes); fixed(byte *bytePtr = rgbValues) { getImageBytes(image, (IntPtr)bytePtr, data.Stride); } // Copy the RGB values back to the bitmap Marshal.Copy(rgbValues, 0, ptr, bytes); bitmap.UnlockBits(data); } return(bitmap); }