This is a migrated thread and some comments may be shown as answers.
Button with Image, how to get image from web site?
2 Answers 45 Views
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 1
Bob asked on 06 Aug 2009, 04:27 PM

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 Answers, 1 is accepted

Sort by
0
Bob
Top achievements
Rank 1
answered on 06 Aug 2009, 05:10 PM
0
Hristo
Telerik team
answered on 07 Aug 2009, 08:14 AM
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.
Asked by
Bob
Top achievements
Rank 1
Answers by
Bob
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or