I have a byte array (imgBuffer) which contains the rgb values for a jpeg image. I would like to save this to a Bitmap. When I use System.IO.File.WriteAllBytes("fileImg.jpg", imgBuffer);
I am able see the image in my directory in its correct format. The image gets corrupted when I try to write the same byte array, imgBuffer, to a Bitmap object. (The image format is 24bpp, 320x240)
BitmapData data;
Bitmap myBitmap = new Bitmap(320, 240, PixelFormat.Format24bppRgb);
//convert bytes to a bitmap
data = myBitmap .LockBits(new Rectangle(Point.Empty, bitmapResized.Size), ImageLockMode.WriteOnly,
PixelFormat.Format24bppRgb);
Marshal.Copy(imgBuffer, 0, data.Scan0, imgBuffer.Length);
myBitmap .UnlockBits(data);
myBitmap .Save("bitmapImg.jpg");
What must I change so that bitmapImg is correctly outputted to my directory? I am currently getting the following corrupted image.