位图转换为图标 [英] Converting Bitmap to Icon
本文介绍了位图转换为图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图将图像从一个位图
转换为Windows图标。这是code。
I'm trying to convert an image from a Bitmap
to a Windows icon. This is the code.
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!");
}
在code工作正常,但问题是,当我将图片转换为转换的图标失去了它的真面目和渐变的图标(图像显示)。那么,有没有任何方式,我可以将图像转换,而不会失去它的颜色?
The code is working fine but the problem is, when I convert the picture to an icon the converted icon loses its true colors and gradients (shown in image). So, is there any way by which I can convert the image without losing its colors?
这是我的图标看起来像。
This is what my icon looks like.
推荐答案
这是与.net一个已知的问题,因为它没有连接codeR的图标。请参阅可能的解决方法如下。
This is a known issue with .Net since it doesn't have an icon encoder. See the following for possible workarounds.
这篇关于位图转换为图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文