請正確解釋您的問題。 「我缺少字節」不是可以解決的問題。你期望什麼數據,你看到了什麼?
Bitmap.Save()
將根據指定的格式返回數據,這些格式在所有情況下都不僅包含像素數據(描述寬度和高度的標題,顏色/調色板數據等)。如果你只想像素數據的數組,你Bimap.LockBits()
最好看看:
Bitmap bmp = new Bitmap("c:\\fakePhoto.jpg");
// Lock the bitmap's bits.
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat);
// Get the address of the first line.
IntPtr ptr = bmpData.Scan0;
// Declare an array to hold the bytes of the bitmap.
int bytes = Math.Abs(bmpData.Stride) * bmp.Height;
byte[] rgbValues = new byte[bytes];
// Copy the RGB values into the array.
System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);
現在rgbValues
數組包含從源位圖的所有像素,每個像素使用3個字節。我不知道你爲什麼想要一些短褲,但你必須能夠從這裏弄清楚。
'512 x 512 x 4 = 1048576'那麼丟失的字節在哪裏? – leppie