Loading an .ico from web and convert to BitmapSource

有些话、适合烂在心里 提交于 2020-01-16 19:36:33

问题


Im trying to load a file of type .ICO from web and use it as an image in my windows phone. But I get an error when trying to set the source of the BitmapImage. Here is my code:

WebClient client = new WebClient(); 
client.OpenReadCompleted += (s, e) => { 
    if (e.Cancelled) return; 
    if (null != e.Error) throw e.Error; 

    BitmapImage image = new BitmapImage(); 
    image.SetSource(e.Result); 
    this.Favicon = image; 
};

client.OpenReadAsync(new Uri(@"http://mysite/myimage.ico", UriKind.RelativeOrAbsolute));

Does BitmapImage support "ico" files? how to convert an "ico" to a supported BitmapImage file.

THe solution must work on Windows Phone 7.

Tks


回答1:


The only formats supported by BitmapImage seem to be PNG and JPG.

Not completely stated here, but implied by the comments: http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapimage(VS.95).aspx

A silverlight implementation of .ico handling is here: http://blogs.msdn.com/b/jstegman/archive/2009/09/13/silverlight-ico-icon-decoder-parser.aspx

You might have to modify it to be compatible with the version of silverlight on Windows Phone 7.



来源:https://stackoverflow.com/questions/4807124/loading-an-ico-from-web-and-convert-to-bitmapsource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!