Copy codeThe Code is as follows: 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 {
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 {
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)
Sport data [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;
}