Runtime Image Conversion (C#) .ICO to .PNG? (.ICO not supported; WWW.texture only accepts .PNG and .JPEG)

Any alternatives? Perhaps I should use WWW.Bytes and somehow transform that array of bytes from .ICO to .PNG?

Quote from Unity3D Docs:

The data must be an image in JPG or PNG format. If the data is not a
valid image, the generated texture will be a small image of a question
mark.

And indeed, that’s what I am getting — a red-question-mark photo! I am 100% sure that I am passing the correct link of the .ICO file and successfully downloading it.

Here’s the download code:

void Update()
{
    if (gotIconURL && !gotIconTexture)
    {
        //StopCoroutine("GetIcon");
        StartCoroutine("GetIcon");
        gotIconURL = false; // We don't have the new/future icon URL
    }
}

IEnumerator GetIcon()
{
    ///NOTE!
    ///Each invocation of texture property allocates a new Texture2D, do something about it! 
    ///If I continously download textures I must use LoadImageIntoTexture or Destroy the previously created texture.
    
    // Start a download of the given URL
    var www = new WWW(iconURL); // e.g. https://www.google.com/favicon.ico
    //Debug.Log(iconURL);

    // Wait for download to complete
    yield return www;

    // Assign texture
    rawIcon.texture = www.texture;

    gotIconTexture = true;
}

Any ideas?

Generally people convert it offline, i.e. using some program and then simply download png (instead of ico or other format). If you really need to support ico, then you will have to find a converter and integrate it into your app. There is no simple solution - Unity has no API for that.

Apparently nobody went through this issue I am having. Suppose I have to convert the image to PNG using something like the answer below and then use Resources.LoadAsset

http://stackoverflow.com/a/10377361

Getting the variable ICON link in real-time was a real headache, let alone converting it now and THEN loading it back into Unity! May the force be with me lol

There’s an asset for that now! Feel free to check out Iconic (.ico Utilities) on the Asset Store.

It allows reading and writing of .ico files to/from Texture2D at runtime. (From a Texture2D you can easily get a PNG by calling ImageConversion.EncodeToPNG(tex)). It’s also cross-platform and does not rely on Systems.Drawing.dll. Here’s a WebGL Demo.

(Disclosure: I’m the developer of that asset. Let me know if you have any questions or issues.)