0

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.

Peter Lee
  • 12,931
  • 11
  • 73
  • 100

1 Answers1

0

Can it be related with UriType ?

Relative,Absolute,RelativeOrAbsolute

ei.UriSource =
new Uri(@"https://www.google.com/images/srpr/logo3w.png"
,UriKind.RelativeOrAbsolute); // works ?

http://msdn.microsoft.com/en-us/library/system.urikind(v=vs.95).aspx

Hope helps!

EDIT: You need a file like that http://twitter.com/crossdomain.xml otherwise SL throws SecurityException normally.

For crossdomain implementation see

https://stackoverflow.com/a/1325011/413032

http://www.silverlighthack.com/post/2008/11/08/Silverlight-clientaccesspolicyxml-files-for-the-Enterprise-(Part-1-of-2).aspx

Community
  • 1
  • 1
Davut Gürbüz
  • 5,526
  • 4
  • 47
  • 83
  • Add ei.LoadingFailed it says why it fails – Davut Gürbüz Nov 19 '12 at 17:16
  • I got System.Security.SecurityException It means you need CrossDomain.xaml http://stackoverflow.com/q/4174317/413032. CrossDomain is a file it says my software can reach this channels.These ports..., These remote files... – Davut Gürbüz Nov 21 '12 at 14:52