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[];
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…