I'm using the ImageTools library (imagetools.codeplex.com) to load an image from external URL.
<Canvas x:Name="LayoutRoot" Background="Blue"
Width="466" Height="204" >
<Image Name="theImage" />
<Button x:Name="btnTest" Canvas.Top="0" Canvas.Left="-200" Click="btnTest_Click"
Width="100" Height="23"
Content="Test Button">
</Button>
</Canvas>
Init:
public MainPage()
{
InitializeComponent();
Encoders.AddEncoder<PngEncoder>();
Decoders.AddDecoder<PngDecoder>();
Encoders.AddEncoder<JpegEncoder>();
Decoders.AddDecoder<JpegDecoder>();
}
Then:
private void btnTest_Click(object sender, RoutedEventArgs e)
{
ExtendedImage ei = new ExtendedImage();
// ei.UriSource = new Uri(@"https://www.google.com/images/srpr/logo3w.png"); // NOT working
ei.UriSource = new Uri(@"/Images/header.png", UriKind.Relative); // Working
ei.LoadingCompleted += new EventHandler((ss, ee) =>
{
Dispatcher.BeginInvoke(() =>
{
theImage.Source = ei.ToBitmap();
});
});
}
I found that loading a local file /Image/header.png
is working, but loading an external URL image (https://www.google.com/images/srpr/logo3w.png
) is not working at all.
It behaves crazy: once I click the Test Button, the LayoutRoot canvas disappears.
However, according to this discussion: http://imagetools.codeplex.com/discussions/250624 Loading an external URL image should be working.