1

我正在开发一个应用程序,我将加载不在 clientbin 文件夹中的图像,但在放置在我的服务器中的文件夹中。我会做这样的事情 BitmapImage bit = new BitmapImage(); 字符串路径 = "c:/image.png"; bit.UriSource = new Uri(path, UriKind.Absolute); 身份。来源=位;但它不起作用。知道吗?谢谢

4

3 回答 3

1

尝试:

Image.Source = New Imaging.BitmapImage(New Uri(" http://www.Pic.jpg ", UriKind.Absolute))

您不想将它包含在您的项目中,否则 .xap 会变得很大。

于 2009-04-09T12:43:18.490 回答
0

Silverlight 应用程序在客户端上运行,而不是在服务器上,因此您一直在尝试引用路径,这将真正指向运行应用程序的客户端计算机上的路径。但是,出于安全原因,Silverlight 无论如何都无权读取或写入客户端磁盘。隔离存储功能是个例外。

因此,您的选择是尝试 Bill 给出的第一个答案,或者 WebService,实现起来更复杂。

ib。

于 2009-04-09T16:04:02.070 回答
0

添加到比尔的答案。您还可以使用以下从 xap 文件位置派生的辅助方法来使用服务器端资源。

public static string GetUrlForResource(string resourcePage)
{

    var webUrl = Application.Current.Host.Source.ToString();
    //Get ClientBin Directory
    var stub = webUrl.Substring(0, webUrl.LastIndexOf("/"));
    //Get application root.
    stub = stub.Substring(0, stub.LastIndexOf("/") + 1);
    //Append the application root to the resource page.
    webUrl = stub + resourcePage;

    return webUrl;
}

要像比尔的答案一样使用它,请使用以下命令:

Image.Source = new Imaging.BitmapImage(new Uri(GetUrlForResource("images/myimage.png"), UriKind.Absolute));
于 2017-01-04T16:15:44.510 回答