Button with Image, how to get image from web site?

3 posts, 0 answers
  1. Bob
    Bob avatar
    55 posts
    Member since:
    Apr 2008

    Posted 06 Aug 2009 Link to this post

    Given the xaml for a image button, I have code to load an image, but this consistantly fails at the call to loadedImage.SetSource(e.Result);// <== Fails here with Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))public void LoadImage(string ImageURL)

     

    {

     

     

    //

     

     

     

     

     

     

     

     

    // Creating WebClient object and setting up events

     

     

     

     

     

     

     

     

    //

     

     

     

     

     

     

     

     

    WebClient downloader = new WebClient();

     

    downloader.OpenReadCompleted +=

     

    new OpenReadCompletedEventHandler(downloader_OpenReadCompleted);

     

     

     

     

     

     

     

    //

     

     

     

     

     

     

     

     

    // Specify Image to load

     

     

     

     

     

     

     

     

    //

     

     

     

     

     

     

    downloader.OpenReadAsync(

     

    new Uri(ImageURL, UriKind.RelativeOrAbsolute));

     

    }

     

     

    void downloader_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)

     

    {

     

     

    //

     

     

     

     

     

     

     

     

    // Create a new BitmapImage and load the stream

     

     

     

     

     

     

     

     

    //

     

     

     

     

     

     

     

     

    try

     

     

     

     

     

     

    {

     

     

     

    BitmapImage loadedImage = new BitmapImage();

     

     

     

    //Image loadedImage = new Image();

     

     

     

     

     

     

    loadedImage.SetSource(e.Result);// <== Fails here with Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))

     

     


    // Setting our BitmapImage as the source of a BackgroundImage control I have in XAML

     

     

     

     

    this.btnImg.Source = loadedImage;

     

     

     

    }

     

     

    catch (Exception)

     

    {

     

     

     

    //ToolTipService.SetToolTip(this.btnButton, new ToolTip { Content = e.Error });

     

     

     

     

     

     

    }

    }

     

     

    <

     

     

    UserControl

     

    xmlns

     

     

    ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

     

    xmlns

     

     

    :x="http://schemas.microsoft.com/winfx/2006/xaml"

     

    x

     

     

    :Class="ImageButtonWLink.MainControl"

     

     

     

    mc:Ignorable="d"

     

     

     

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

     

     

     

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

     

     

     

    Height="40" Width="200">

     

     

     

     

     

    <Canvas x:Name="cnvLayoutRoot" Background="{x:Null}" >

     

     

     

     

    <Button x:Name="btnButton" Background="White" Width="199.991" Canvas.Top="-0.009" Canvas.Left="-0.009" Click="btnClickEvent" Height="40" >

     

     

     

     

    <StackPanel x:Name="spnlButtonContent" VerticalAlignment="Center" Orientation="Horizontal" Width="195.138">

     

     

     

     

    <Image x:Name="btnImg" Width="30" Height="30" Source="/ImageButtonWLink;component/Images/Comments-info.png" Stretch="None" />

     

     

     

     

    <TextBlock x:Name="btnText" Text="Set text via btnText " FontWeight="Bold" Foreground="#1ca0f2" VerticalAlignment="Center" Width="159.84" HorizontalAlignment="Stretch" Padding="4" />

     

     

     

     

    </StackPanel>

     

     

     

     

    </Button>

     

     

     

     

     

    </Canvas>

     

    </

     

     

    UserControl>

     

  2. Bob
    Bob avatar
    55 posts
    Member since:
    Apr 2008
  3. DevCraft banner
  4. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 07 Aug 2009 Link to this post

    Hello Bob,

    Unfortunately Silverlight support only jpg and png as image formats.
    We can only hope that Microsoft will add support for more formats.

    Sincerely yours,
    Hristo
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top