我正在获取 json 数据,其中有一个链接可以再次获取图像
例如:
{"status":"403","message":"Not Authorized","image":"http:\/\/abc.com\/images\/1.jpg"}
状态、消息 n 图像的检索非常好,因为我在文本框中显示了值。
此外,我想显示图像,所以我这样做:
public string link = ClassName.variableName;
link
现在的值是 http//abc.com/images/1.jpg
。我在文本框中显示了它的值并且很好。所以我更进一步:
BitMapImage MyImage = new BitMapImage( new Uri (link, UriKind.RelativeOrAbsolute));
image1.source = MyImage;
但是当我运行它时,它显示错误“UnAuthorized access exception unhandled”。为了进行交叉检查,我打开了一个新项目,并没有获取数据,而是直接提供了图像源的链接并显示了图像。
BitMapImage MyImage = new BitMapImage( new Uri ("http//abc.com/images/1.jpg", UriKind.RelativeOrAbsolute));
image1.source = MyImage;
在这里它工作正常。显示图像。
最佳答案
我没有使用 Deployment.Current.Dispatcher.BeginInvoke(() => 现在它工作正常。
关于c# - 获取图片,未授权访问异常错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14630179/