kak*_*ott 11 c# icons image bitmap winforms
我正在尝试将图像从BitmapWindows图标转换为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!");
}
Run Code Online (Sandbox Code Playgroud)
代码工作正常,但问题是,当我将图片转换为图标时,转换后的图标会丢失其真实颜色和渐变(如图所示).那么,有没有什么方法可以转换图像而不会失去它的颜色?
这就是我的图标.

| 归档时间: |
|
| 查看次数: |
5974 次 |
| 最近记录: |