从位图到图标的图像转换似乎不起作用
我有一个简单的函数,它接受位图,并将位图转换为 ICON 格式。下面是该函数。 (我用文字值代替变量)
Bitmap tempBmp = new Bitmap(@"C:\temp\mypicture.jpeg");
Bitmap bmp = new Bitmap(tempBmp, 16, 16);
bmp.Save("@C:\temp\mypicture2.ico", ImageFormat.Icon)
它似乎没有正确转换......或者我认为是这样。图像转换后,某些浏览器不会将图像重新识别为真正的“ICON”,甚至 Visual Studio 2008 在将图像转换为 Icon 格式后也不会将图像重新识别为图标。
例如,我打算使用刚刚转换的图标为我的 Win32 表单应用程序设置 Icon 属性。我打开对话框并选择刚刚转换的图标并收到以下错误。
--“参数‘图片’必须是可以用作图标的图片。”
我浏览过网络并遇到过复杂的代码,人们花时间手动将位图转换为不同的格式,但我认为上面的代码应该可以工作,并且 .NET 框架会处理这种转换。
I have a simple function that takes a bitmap, and converts the bitmap to an ICON format. Below is the function. (I placed literal values in place of the variables)
Bitmap tempBmp = new Bitmap(@"C:\temp\mypicture.jpeg");
Bitmap bmp = new Bitmap(tempBmp, 16, 16);
bmp.Save("@C:\temp\mypicture2.ico", ImageFormat.Icon)
It doesn't seem to be converting correctly...or so I think. After the image is converted, some browsers do not reconigze the image as a true "ICON" , and even Visual Studio 2008 doesn't reconigze the image as an icon after its converted to an Icon format.
For example, I was going to set the Icon property for my Win32 form app with the Icon i just converted. I open the dialouge box and select the icon I just converted and get the following error.
-- "Argument 'picture' must be a picture that can be used as a Icon."
I've browsed the web and come across complicated code where people take the time to manually convert the bitmap to different formats, but I would think the above code should work, and that the .NET framework would take care of this conversion.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我测试了以下代码并且它有效,但结果不是很好。请记住,图标的调色板有限,您可能会丢失一些颜色信息。
I tested the following code and it worked but the results weren't great. Remember an icon has a limited palette and you'll probably lose some color information.