I am trying to create a bitmap object from raw bytes, my PixelFormat is RGB with 8 bits per sample, which is 3 bytes per pixel. now for this my stide will be 3 times the width.
But Bitmap class is always looking for multiplier of 4 for stride value. Please help me how to resolve this issues. if i give multiplier of 4 image is not coming properly.
Bitmap im = new Bitmap(MyOBJ.PixelData.Columns, MyOBJ.PixelData.Rows, (MyOBJ.PixelData.Columns*3),
System.Drawing.Imaging.PixelFormat.Format24bppRgb, Marshal.UnsafeAddrOfPinnedArrayElement(images[imageIndex], 0));
I’ve written a short sample which will pad every line of your array to adapt it to the required format. It will create a 2×2 check board bitmap.
The
PadLinesmethod is written below. I tried to optimize it by usingBuffer.BlockCopyin case your bitmaps are large.