我对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;
}
}