0
我有一個問題,在C#中使用Lockbits方法.. 我有一個1bpp圖像,我試圖訪問圖像的所有像素,但仍有一些出。移動通過每個像素爲1bpp像素格式
public Bitmap Pixels(Bitmap original)
{
Rectangle rect = new Rectangle(0, 0, original.Width, original.Height);
BitmapData bimgData = original.LockBits(rect, ImageLockMode.ReadWrite, original.PixelFormat);
IntPtr ptr = bimgData.Scan0;
int bytes = bimgData.Stride * bimg.Height;
byte[] Values = new byte[bytes];
Marshal.Copy(ptr, Values, 0, bytes);
int Val;
int stride = bimgData.Stride;
for (int column = 0; column < bimgData.Height; column = column + 1)
for (int row = 0; row < bimgData.Width; row = row +1)
{
c = column;
r = row;
for (int t = 0; t < 8; t++)
{
Val = Values[((c) * stride) + ((r)/8)] & 2^t;
if (Val == 0)
Values[((c) * stride) + ((r)/8)] = (byte)(Values[((c) * stride) + ((r)/8)] + 2^t);
}
}
Marshal.Copy(Values, 0, ptr, bytes);
original.UnlockBits(bimgData);
return original;
}
此代碼應把所有的白色
謝謝!!!!我只是暫時把像素變成白色來理解代碼...... – Afifa