请教高手c#中bitmap转灰度的几个问题
1.public void handlepic( ref Bitmap img )
{
width = img.Width;
height = img.Height;
int fW = ( ( ( width - 1 ) / 8 ) + 1 );
int fH = ( ( ( height - 1 ) / 8 ) + 1 );
int len = fW * fH;
}
这里的 FW 和 FH;width和height;len分别代表什么意思?
2.(接上输代码)
{
BitmapData data = image.LockBits(
new Rectangle( 0, 0, width, height ),
ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb );
private byte[] buf = null;
int offset = stride-width * 3;
int len = (int)( ( width-1 ) / 8 ) + 1;
int rem = ( (width -1 ) % 8 ) + 1;
int[] tmp = new int[len];
int i, j, t1, t2, k = 0;
unsafe
{
byte * src = (byte *) data.Scan0.ToPointer( );
for ( int y = 0; y < height; )
{
Array.Clear( tmp, 0, len );
for ( i = 0; ( i < 8 ) && ( y < height ); i++, y++ )
{
for ( int x = 0; x < width; x++, src += 3 )
{
tmp[(int) ( x / 8 )] += (int)( 0.2125f * src[RGB.R] + 0.7154f * src[RGB.G] + 0.0721f * src[RGB.B] );
}
src += offset;
}
// get average values
t1 = i * 8;
t2 = i * rem;
for ( j = 0; j < len - 1; j++, k++ )
buf[k] = (byte)( tmp[j] / t1 );
buf[k++] = (byte)( tmp[j] / t2 );
}
}
这里的 rem?tmp[(int) ( x / 8 )]和t1,t2 有什么意义?求指点~