我想一個位圖轉換爲Format24bppRgb。 因爲我需要爲每個像素設置一組顏色數組,所以我使用了不安全的代碼。轉換位圖到Format24bppRgb
問題是,位圖以某種方式轉換爲Jpeg。 當我查看顏色數組時,一些人在黑人和白人之間有一種奇怪的顏色(黃色或藍色)。
是有辦法防止變色?
//image
mstr = new MemoryStream(msgSet.VMSPage2Image);
bitmapFile = new Bitmap(mstr);
data = bitmapFile.LockBits(new Rectangle(0, 0, bitmapFile.Width, bitmapFile.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
colors = new Color[data.Height, data.Width];
unsafe
{
byte* imgPtr = (byte*)(data.Scan0);
for (int i = 0; i < data.Height; i++)
{
for (int j = 0; j < data.Width; j++)
{
// write the logic implementation here
imgPtr += 1;
int G = *imgPtr;
imgPtr += 1;
int R = *imgPtr;
imgPtr += 1;
int B = *imgPtr;
colors[i, j] = Color.FromArgb(R, G, B);
}
imgPtr += data.Stride - data.Width * 3;
}
}
http://stackoverflow.com/questions/2003643/how-is-1-bit-bitmap-data-converted-to-8bit-24bpp – 2011-01-24 20:47:48