从Web加载.ico并转换为BitmapSource [英] Loading an .ico from web and convert to BitmapSource

查看:159
本文介绍了从Web加载.ico并转换为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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆