【发布时间】:2012-07-23 03:57:32
【问题描述】:
我正在尝试将图像从 Bitmap 转换为 Windows 图标。这是代码。
private void btnCnvrtSave_Click(object sender, EventArgs e)
{
Bitmap bmp = (Bitmap)picturePanel.BackgroundImage;
Bitmap newBmp = new Bitmap(bmp);
Bitmap targetBmp = newBmp.Clone(new Rectangle(0, 0, newBmp.Width, newBmp.Height), PixelFormat.Format64bppArgb);
IntPtr Hicon = targetBmp.GetHicon();
Icon myIcon = Icon.FromHandle(Hicon);
SaveFileDialog sfd = new SaveFileDialog();
sfd.Title = "Save Icon";
sfd.Filter = "Icon|*.ico";
sfd.ShowDialog();
FileStream fileStream = new FileStream(sfd.FileName,FileMode.OpenOrCreate);
myIcon.Save(fileStream);
fileStream.Flush();
fileStream.Close();
MessageBox.Show("Image is converted successfully!");
}
代码工作正常,但问题是,当我将图片转换为图标时,转换后的图标会失去其真实颜色和渐变(如图所示)。那么,有什么方法可以在不丢失颜色的情况下转换图像?
这就是我的图标的样子。
【问题讨论】:
-
这看起来像基本的 4bpp 调色板。我不知道为什么会这样。
-
从句柄创建Icon怎么样?
-
不知道怎么做,好的,我会尝试在谷歌中搜索。如果您有任何示例链接..请提供。谢谢。
标签: c# winforms image bitmap icons