gpt4 book ai didi

c# - Monodroid BitmapFactory.DecodeFileDescriptor 位图始终为 null

转载 作者:行者123 更新时间:2023-12-01 14:57:18 28 4
gpt4 key购买 nike

我使用以下方法来防止内存不足异常,但位图始终为空。有人有想法吗?

public Bitmap readBitmap(Android.Net.Uri selectedImage) {

Bitmap bm = null;
BitmapFactory.Options options = new BitmapFactory.Options();
options.InSampleSize = 9;
AssetFileDescriptor fileDescriptor = null;
try {
fileDescriptor = this.ContentResolver.OpenAssetFileDescriptor(selectedImage,"r");
} catch (FileNotFoundException e) {
Toast.MakeText(this, e.Message, ToastLength.Long);
}
finally{
try {
bm = BitmapFactory.DecodeFileDescriptor(fileDescriptor.FileDescriptor, null, options);
fileDescriptor.Close();
} catch (IOException) {
}
}
return bm;
}

最佳答案

是的。这是谷歌的另一个错误。解决方案是这样做:

bm =  BitmapFactory.decodeStream(new FileInputStream(fileDescriptor));

而不是

bm =  BitmapFactory.DecodeFileDescriptor(fileDescriptor.FileDescriptor, null, options);

关于c# - Monodroid BitmapFactory.DecodeFileDescriptor 位图始终为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14193470/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com