'C# Argument 'picture' must be a picture that can be used as an Icon
I am having trouble importing an icon into my application. I have a main form and I am trying to import to it a new icon via the Icon field in Properties.
The image is already in .ico format: this is the link to the icon I'm trying to use.
Does anyone know why Microsoft Visual Studio would be displaying this error?

Any help would be great.
Solution 1:[1]
I had this error recently. Some recommendations:
- make sure the icon is square (16x16, 32x32)
- try saving it to a PNG and using this free service for conversion : http://www.convertico.com/
Solution 2:[2]
We have an application that works fine on 99% of our computers, but in one laptop it pops out this error.
It looks like our issue is that the laptop user set the screen text/image size to 150%. This could cause otherwise working images no longer working. We will see whether this works.
UPDATE
A commenter seems to have the same problem. And yes, we resolved this problem by setting the screen text size to less than 150%.
Solution 3:[3]
Credits to Xiaohuan ZHOU for the answer in this question. This function losslessly converts PNG (including transparency) to .ICO file format.
public void ConvertToIco(Image img, string file, int size)
{
Icon icon;
using (var msImg = new MemoryStream())
using (var msIco = new MemoryStream())
{
img.Save(msImg, ImageFormat.Png);
using (var bw = new BinaryWriter(msIco))
{
bw.Write((short)0); //0-1 reserved
bw.Write((short)1); //2-3 image type, 1 = icon, 2 = cursor
bw.Write((short)1); //4-5 number of images
bw.Write((byte)size); //6 image width
bw.Write((byte)size); //7 image height
bw.Write((byte)0); //8 number of colors
bw.Write((byte)0); //9 reserved
bw.Write((short)0); //10-11 color planes
bw.Write((short)32); //12-13 bits per pixel
bw.Write((int)msImg.Length); //14-17 size of image data
bw.Write(22); //18-21 offset of image data
bw.Write(msImg.ToArray()); // write image data
bw.Flush();
bw.Seek(0, SeekOrigin.Begin);
icon = new Icon(msIco);
}
}
using (var fs = new FileStream(file, FileMode.Create, FileAccess.Write))
{
icon.Save(fs);
}
}
Solution 4:[4]
In my situation the error was because I used a stream and didn't ensure that the stream pointer is at the beginning.
Adding the following line before new Icon(stream) solved the problem:
stream.Seek(0, SeekOrigin.Begin);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | |
| Solution 3 | Stefan ÄorÄ‘ević |
| Solution 4 | yoel halb |
