xamarin - Xamarin:CGImageSource.FromUrl 返回 null
问题描述
我在我的应用程序中使用以下代码。
string imageUrl = "https://imageUrl.png/"; //This is a valid url. I can see the image when I paste the url into my web browser
var url = new NSUrl(imageUrl);
using (CGImageSource source = CGImageSource.FromUrl(url))
{
if (source != null)
{
//I never get here
}
}
为什么source
总是为空?我尝试了很多不同imageUrls
的方法,结果都一样。
解决方案
你的照片地址好像是HTTPS前缀,和HTTP不一样。你可以试试别的URL是HTTP前缀。如果地址必须是HTTPS,我建议你使用一些SDK。
或者您可以使用以下代码,它们在使用 http 时有效
string str = ""; //your image url
NSData ImageData = NSData.FromUrl(new NSUrl(str) );
UIImage image = new UIImage(ImageData);
if (image != null)
{
Console.Write("success");
}
else
{
Console.Write("fail");
}
推荐阅读
- git - 如何将我对克隆的 Github 存储库的编辑推送到我自己的存储库?
- python - 为什么我用opencv的VideoWriter复制视频时,数据变得非常大,是原始视频的6倍
- reactjs - 如何使用 React 从 mongoose 读取 api
- laravel - 如何通过post方法从邮递员的原始数据中保存和下载视频文件等文件
- mysql - 如何在 MYSQL 中为每个提交日期选择最高贡献者
- javascript - 如何在 Cloud Firestore 中有效地获取集合的所有文档及其子集合
- python - 如何检查元素h2是否包含文本
- python - 如何使用 Mayavi 在 python 中为 3D 数据制作动画
- html - 已选中和未选中复选框的值传递给 Django 视图
- excel - 搜索错误,填充数组并呈现类似于视图的枢轴