c# - SkAndroidCodec::NewFromStream 返回 null System.IO.Stream Xamarin Android
问题描述
我有一个关于 BitmapFactory 的问题。我正在使用 Xamarin,并且正在尝试解码从内部存储中检索到的流,但是每当我尝试使用位图工厂进行解码时,它都不会返回位图。但是,如果我从 URL 中检索完全相同的图像并使用 Bitmap Factory 进行解码,它就可以正常工作。这没有任何意义,请帮助!
public static async Task<Bitmap> HandleContentImage(Post post)
{
var charsToRemove = new string[] { "/", ".com", ":", "-", ".", "_", ";" };
var ContentImageUri = post.image_url;
foreach (var c in charsToRemove)
{
ContentImageUri = ContentImageUri.Replace(c, string.Empty);
}
HomeService homeService = new HomeService();
try
{
Stream CachedContentImageStream = await homeService.LoadImageFromCache(ContentImageUri + ".jpg");
if (CachedContentImageStream != null)
{
Bitmap ContentImageBitmap = await BitmapFactory.DecodeStreamAsync(CachedContentImageStream);
return ContentImageBitmap;
}
else
{
byte[] ContentImageArray = await homeService.DownloadImageBytesAsync(post.image_url);
Stream ContentImageStream = new MemoryStream(ContentImageArray);
await homeService.SaveImageToCache(ContentImageStream, ContentImageUri + ".jpg");
Bitmap ContentImageBitmap = await BitmapFactory.DecodeStreamAsync(ContentImageStream);
return ContentImageBitmap;
}
}
catch (Exception e)
{
Console.WriteLine("Error: " + e.Message);
return null;
}
}
解决方案
推荐阅读
- java - 使用 HTML 表单将 BLOB 上传到 MySQL
- python - 如何在 GraalVM 中使用 Python
- javascript - Firestore 查询:查询是否会在没有订阅的情况下使用数据?
- oracle - Oracle Client_charset
- reactjs - 如何使用 React 和 Django 使用环境变量正确保护 API 登录凭据
- angular - ngx markdown 语法高亮 C# 不高亮
- javascript - 如何修复javascript中的循环引用
- api - 邮递员 GET 选项有效,但使用 cURL 命令行失败
- python - 检查数字是否有小数的最快方法
- c++ - 为什么通过 boost::iostreams::filtering_istream 窥视 std::cin 会永远阻塞?