Silverlight Windows Phone 7:从URL加载图像

Len*_*ers 12 silverlight windows-phone-7

我得到下面的代码,试图将图像从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;
        }
Run Code Online (Sandbox Code Playgroud)

适用于Windows Phone 7的Silverlight

Ant*_*nes 12

尝试使用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);
}
Run Code Online (Sandbox Code Playgroud)


Gra*_*ury 3

我看到您正在从该网站检索图像,Dilbert.com该网站是否有跨域策略文件?