The following picture shows what happens when we convert a 24-bit color image of size 1x2.
.
The following picture shows what happens when we convert a a 32-bit color image of size 1x2.
I thought, 24-bit image will occupy 6-bytes. But, both are taking 8-bytes.
As a result, my C# code is failing. Coz, it assumes that a pixel needs (ColorDepth/8)*Width*Height
number of bytes.
public static int[,] ToInteger(Bitmap bitmap)
{
BitmapLocker locker = new BitmapLocker(bitmap);
locker.Lock();
byte[] data = locker.ImageData;
int Width = locker.Width;
int Height = locker.Height;
int noOfBytesPerPixel = locker.BytesPerPixel;
int[,] integerImage = new int[Width, Height];
int byteCounter = 0;
for (int i = 0; i < Width; i++)
{
for (int j = 0; j < Height; j++)
{
int integer = BitConverter.ToInt32(data, byteCounter);
integerImage[i, j] = integer;
byteCounter += noOfBytesPerPixel;
}
}
locker.Unlock();
return integerImage;
}
So, what is going on really?