我在windows xp下創建圖標有問題。 這是我的代碼:在windows xp下創建位圖圖標
void SaveAsIcon(Bitmap SourceBitmap, string FilePath)
{
FileStream FS = new FileStream(FilePath, FileMode.Create);
// ICO header
FS.WriteByte(0); FS.WriteByte(0);
FS.WriteByte(1); FS.WriteByte(0);
FS.WriteByte(1); FS.WriteByte(0);
// Image size
FS.WriteByte((byte)SourceBitmap.Width);
FS.WriteByte((byte)SourceBitmap.Height);
// Palette
FS.WriteByte(0);
// Reserved
FS.WriteByte(0);
// Number of color planes
FS.WriteByte(0); FS.WriteByte(0);
// Bits per pixel
FS.WriteByte(32); FS.WriteByte(0);
// Data size, will be written after the data
FS.WriteByte(0);
FS.WriteByte(0);
FS.WriteByte(0);
FS.WriteByte(0);
// Offset to image data, fixed at 22
FS.WriteByte(22);
FS.WriteByte(0);
FS.WriteByte(0);
FS.WriteByte(0);
// Writing actual data
SourceBitmap.Save(FS, ImageFormat.Png);
// Getting data length (file length minus header)
long Len = FS.Length - 22;
// Write it in the correct place
FS.Seek(14, SeekOrigin.Begin);
FS.WriteByte((byte)Len);
FS.WriteByte((byte)(Len >> 8));
FS.Close();
}
它在Vista和更高版本下工作正常。
我不知道我應該改變我的方法來創建從Windows XP位圖圖標。
當我試着使用方法使用上面的圖標我得到這個錯誤:
錯誤生成Win32資源:讀取錯誤圖標
在Vista下,7,8它的工作原理。
你從哪裏得到這個錯誤?我認爲圖標需要ico文件 – Sayse
我在c#中動態編譯期間出現此錯誤。 CompilerParameters cp = new CompilerParameters(); cp.CompilerOptions =「/ optimize/warn:4/target:winexe /win32icon:icon.ico」; – Yozer