微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Silverlight Windows Phone 7:从URL加载图像

我得到了下面的代码,试图将图像从Web加载到 Image控件中,当我运行它时,我在给定的线路上收到不允许网络访问错误

private void button1_Click(object sender,RoutedEventArgs e)
        {
            WebClient webClientImgDownloader = new WebClient();
            webClientImgDownloader.OpenReadCompleted += new OpenReadCompletedEventHandler(webClientImgDownloader_OpenReadCompleted);
            webClientImgDownloader.OpenReadAsync(new Uri("http://dilbert.com/dyn/str_strip/000000000/00000000/0000000/000000/80000/5000/100/85108/85108.strip.print.gif",UriKind.Absolute));
        }

        void webClientImgDownloader_OpenReadCompleted(object sender,OpenReadCompletedEventArgs e)
        {
            BitmapImage bitmap = new BitmapImage();
            bitmap.SetSource(e.Result); // ERROR HERE!
            image1.source = bitmap;
        }

Silverlight for Windows Phone 7

解决方法

尝试使用WebClient下载内容将需要客户端访问策略文件存在于源服务器上.对于图像,您可以通过以下方式避免此要求: –

private void button1_Click(object sender,RoutedEventArgs e)
{
    Uri uri = new Uri("http://dilbert.com/dyn/str_strip/000000000/00000000/0000000/000000/80000/5000/100/85108/85108.strip.print.gif",UriKind.Absolute)
    image1.source = new BitmapImage(uri);
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐