在运行 Android 10 的模拟器上,当我在 FireDescriptor 上使用decodeFileDescriptor(如下所示)时,位图创建得很好。但是,当我尝试设置选项,然后使用该选项对象获取位图时,选项对象似乎没有正确设置,并且位图为空。请让我知道我做错了什么。感谢您的帮助。
Bitmap test1c = BitmapFactory.decodeFileDescriptor(fdCompressed);
//This works
testImgView.setImageBitmap(test1c);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFileDescriptor(fdCompressed, null, options);
//The line above sets outHeight and outWidth of options to -1
options.inJustDecodeBounds = false;
//This bitmap object is null
Bitmap test1e = BitmapFactory.decodeFileDescriptor(fdCompressed, null, options);
testImgView.setImageBitmap(test1e);
最佳答案
找到了它不起作用的原因。我一开始所做的测试导致了这个问题。
Bitmap test1c = BitmapFactory.decodeFileDescriptor(fdCompressed);
因为看起来ParcelFileDescriptor对象只能使用一次来生成Bitmap。当我删除那条线并尝试时,效果很好。我花了几个小时才弄清楚这一点,希望它对某人有所帮助。
关于bitmapfactory - Android 10 : BitmapFactory. 解码文件描述符返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61340166/