private void ReadImage()
{
int i, j;
GreyImage = new int[Width, Height]; //[Row,Column]
Bitmap image = Obj;
BitmapData bitmapData1 = image.LockBits(new Rectangle(0, 0, image.Width, image.Height),
ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
unsafe
{
byte* imagePointer1 = (byte*)bitmapData1.Scan0;
for (i = 0; i < bitmapData1.Height; i++)
{
for (j = 0; j < bitmapData1.Width; j++)
{
GreyImage[j, i] = (int)((imagePointer1[0] + imagePointer1[1] + imagePointer1[2]) / 3.0);
//4 bytes per pixel
imagePointer1 += 4;
}//end for j
//4 bytes per pixel
imagePointer1 += bitmapData1.Stride - (bitmapData1.Width * 4);
}//end for i
}//end unsafe
image.UnlockBits(bitmapData1);
return;
}
the line GreyImage[j,i] = (int)((imagePointer1[0] .....
seems to be reading into the byte*
like an array, obviously I can't assign an unsafe bit of code to an array for later processing, so i thought maybe just assign those 4 bytes to the array.
How do you assign those 4 bytes to the array?
i thought by doing:
var imageData = new byte[Width, Height][];
imageData[x,y] = pixelSet //basically byte[];
I think you are trying to do something like this. Obviously, I haven't tested this code but it will get you in the direction you want.
OR
A pointer to an array always points to element zero. You can access other elements by adding to the pointer or incrementing the pointer.
Plus and minus move the pointer reference by the number of bytes that make up the sizeof the array's data type. If it was an int[], + and - would move the pointer in increments of 4 bytes.