我在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