Silverlight:ImageTools.ExtendedImage加载外部URL图像根本不工作
我正在使用ImageTools库(ImageTools.codeplex.com)从外部URL加载图像Silverlight:ImageTools.ExtendedImage加载外部URL图像根本不工作,image,silverlight,url,Image,Silverlight,Url,我正在使用ImageTools库(ImageTools.codeplex.com)从外部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="
<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>
我发现加载本地文件/Image/header.png
是可行的,但加载外部URL图像(https://www.google.com/images/srpr/logo3w.png
)根本不起作用
它的行为很疯狂:一旦我单击测试按钮,LayoutRoot画布就会消失
然而,根据这一讨论:
加载外部URL映像应该可以正常工作。它是否与UriType相关 相对溶质
ei.UriSource =
new Uri(@"https://www.google.com/images/srpr/logo3w.png"
,UriKind.RelativeOrAbsolute); // works ?
希望有帮助
编辑:您需要这样的文件,否则SL通常会抛出SecurityException
有关跨域实现,请参阅
Add ei.LoadingFailed它说明了失败的原因我得到了System.Security.SecurityException它意味着你需要CrossDomain.xaml。CrossDomain是一个文件,它说我的软件可以到达这个通道。这些端口…,这些远程文件。。。
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();
});
});
}
ei.UriSource =
new Uri(@"https://www.google.com/images/srpr/logo3w.png"
,UriKind.RelativeOrAbsolute); // works ?