读取图片像素的具体实例
public static short[][] getpixs(bitmap bitmap)
{
int height = bitmap.height;
int width = bitmap.width;
byte tempb, tempg, tempr;
short[][] sporigindata = new short[height][];
for (int i = 0; i < height; i++)
{
sporigindata[i] = new short[width];
}
bitmapdata dataout = bitmap.lockbits(new rectangle(0, 0, width, height), imagelockmode.readwrite, pixelformat.format24bpprgb);
int offset = dataout.stride - dataout.width * 3;
try
{
unsafe
{
byte* pout = (byte*)(dataout.scan0.topointer());
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
tempb = pout[0];
tempg = pout[1];
tempr = pout[2];
double data=0.31 * tempr + 0.59 * tempg + 0.11 * tempb;
if (data > 255)
sporigindata[y][x] = 255;
else
if (data < 0)
sporigindata[y][x] = 0;
else
sporigindata[y][x] = (short)data;
pout += 3;
}
pout += offset;
}
bitmap.unlockbits(dataout);
}
}
catch
{
}
return sporigindata;
}