Silverlight Windows Phone 7: Load Images From URL

前端 未结 4 1594
花落未央
花落未央 2021-02-05 17:40

I got the code below that is trying to load an image from the web into an Image control, when I run it I get an error on the given line that no network access is allowed:

<
相关标签:
4条回答
  • 2021-02-05 18:24

    Can you give us the full exception stack trace? the error could be that your phone emulator does not have internet access, or it could be the image on the dilbert server that does not allow anonymous requests that did not originate from their site ... so guidance on a solution will differ :-)

    0 讨论(0)
  • 2021-02-05 18:25

    Trying to download content with WebClient will require a client access policy file to be present on the source server. For images you can avoid this requirement by doing it like this:-

    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);
    }
    
    0 讨论(0)
  • 2021-02-05 18:28

    I see you're retrieving the image from Dilbert.com does that site have a cross domain policy file?

    0 讨论(0)
  • 2021-02-05 18:39

    Silverlight doesn't support GIF only JPG, so I wrote:

    www.lenniedevilliers.net/displaygif.aspx?link=http://dilbert.com/dyn/str_strip/000000000/00000000/0000000/000000/80000/5000/100/85108/85108.strip.print.gif

    the displaygif.aspx page convert the GIF into a JPG.

    0 讨论(0)
提交回复
热议问题