开发者

Image Conversion from Bitmap to Icon doesn't seem to work

开发者 https://www.devze.com 2022-12-27 03:00 出处:网络
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)开发者_运维知识库

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.


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.

    Bitmap b = new Bitmap(@"d:\file.jpg");
    Icon i = Icon.FromHandle(b.GetHicon());
    i.Save(File.Open(@"d:\file.ico", FileMode.OpenOrCreate, FileAccess.Write));
0

精彩评论

暂无评论...
验证码 换一张
取 消