1

I am trying to set the source of images as follows :

    private void buttonGet_Click(object sender, RoutedEventArgs e)
    {
        string website_url =HttpUtility.UrlEncode( textBoxURL.Text);
        WebClient wc = new WebClient();
        wc.OpenReadCompleted += new OpenReadCompletedEventHandler(wc_OpenReadCompleted);
        Uri favIconUri = new Uri("http://g.etfv.co/"+ website_url ,UriKind.Absolute);
        wc.OpenReadAsync(favIconUri, wc);

    }
void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {
        if (e.Error == null && !e.Cancelled)
        {
            try
            {

                BitmapImage image = new BitmapImage();
                image.SetSource(e.Result);
                image1.Source = image;
            }
            catch (Exception ex)
            {
                //Exception handle appropriately for your app  
                int i = 0;
            }
        }
        else
        {
            //Either cancelled or error handle appropriately for your app  
        }
    }
}

I get exception : {"The request is not supported. "} in line image.SetSource(e.Result);

The text box url is "http://google.com" so the url formed is : "http://g.etfv.co/http%3a%2f%2fwww.google.com" I am unable to figure out a simple thing.

I tried with simple url as "http://img.technospot.net/Windows-Phone-7-Theme-Symbian.jpg" (instead of "http://g.etfv.co/foo-bar" and then it works but not the way I coded.

Anything incorrect ?

3
  • Why not just do new BitmapImage(favIconUri)? Commented Mar 17, 2012 at 13:54
  • tried that .. doesn't work. I wanted to show some progress etc Commented Mar 17, 2012 at 13:58
  • 1
    The image doesn't appear nor does it throw an error in that case Commented Mar 17, 2012 at 14:00

1 Answer 1

4

Your problem is that the image that is returned is of type "ICO" which is not supported by BitmapSource. Only PNG and JPEG are supported.

Other formats such as GIF and ICO can only be read using a custom decoder.

Try using a different service to get the favicon:

http://www.getfavicon.org/results.php?url=google.com&t=png

will give you a PNG which BitmapSource will happily load.

Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.