2
我想在C#中創建一個4位的PNG文件,但我的代碼不起作用。如何使用C#創建4位PNG?
下面是代碼:
Bitmap bmp = new Bitmap(200, 50, PixelFormat.Format4bppIndexed);
string f = bmp.PixelFormat.ToString();
Graphics gImage = Graphics.FromImage(bmp);
gImage.FillRectangle(Brushes.Red, 0, 0, bmp.Width - 20, bmp.Height - 20);
gImage.DrawRectangle(Pens.White, 0, 0, bmp.Width - 20, bmp.Height - 20);
gImage.DrawString("Test", SystemFonts.DefaultFont, Brushes.White, 5, 8);
bmp.Save("C:\\buttons_normal1.png",ImageFormat.Png);
的代碼拋出在圖形gImage線異常因的PixelFormat設置爲Format4bppIndexed。我在這裏看到了一個解決方案,提示最終的位圖可以轉換爲4位,但該代碼從未爲我工作。
有什麼建議嗎?
你可以請發表樣本代碼如何複製每個像素? – 2011-01-11 08:44:39