當我創建這樣的位圖:.bmp是不是一個Windows位圖?
Unknown file type! H:\test.bmp is not a Windows BMP file!
但在Windows我可以打開的文件:
var testImage = new Bitmap(320, 240);
var testDataLock = testImage.LockBits(new Rectangle(new Point(), testImage.Size),
System.Drawing.Imaging.ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
unsafe
{
var aaa = CamData.ToArray();
UInt32 lOffset = 0;
UInt32 lPos = 0;
byte* lDst = (byte*)testDataLock.Scan0;
byte bitshift = 8;
fixed (UInt16* lSrc = aaa)
{
while (lOffset < testImage.Width * testImage.Height)
{
lDst[lPos] = (byte)(lSrc[lOffset] >> bitshift);
lDst[lPos + 1] = lDst[lPos];
lDst[lPos + 2] = lDst[lPos];
lOffset++;
lPos += 3;
// take care of the padding in the destination bitmap
if ((lOffset % testImage.Width) == 0)
lPos += (UInt32)testDataLock.Stride - (uint)(testImage.Width * 3);
}
}
}
testImage.UnlockBits(testDataLock);
testImage.Save(@"H:\Test.bmp");
試圖打開該文件與可視化的lib我送花兒給人得到一個錯誤查看器等...沒有問題 有人知道我爲什麼會得到這個錯誤嗎?
感謝
這個。我不確定默認情況下會選擇哪種格式,但明確說明總是很好的。 – 2011-04-20 08:09:38
哦,這麼容易:),謝謝:) – h0ppel 2011-04-20 08:14:50