从Web加载.ico并转换为BitmapSource [英] Loading an .ico from web and convert to BitmapSource
问题描述
我正在尝试从Web加载.ICO类型的文件,并将其用作Windows Phone中的图像.但是尝试设置BitmapImage的源时出现错误.这是我的代码:
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));
BitmapImage是否支持"ico"文件?如何将"ico"转换为受支持的BitmapImage文件.
Does BitmapImage support "ico" files? how to convert an "ico" to a supported BitmapImage file.
该解决方案必须在Windows Phone 7上运行.
THe solution must work on Windows Phone 7.
Tks
推荐答案
BitmapImage
支持的唯一格式似乎是PNG和JPG.
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
.ico处理的Silverlight实现在这里: http://blogs .msdn.com/b/jstegman/archive/2009/09/13/silverlight-ico-icon-decoder-parser.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
您可能需要修改它以使其与Windows Phone 7上的silverlight版本兼容.
You might have to modify it to be compatible with the version of silverlight on Windows Phone 7.
这篇关于从Web加载.ico并转换为BitmapSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!