在运行Android 10的仿真器上,当我如下所示在FireDescriptor上使用解码文件描述符时,可以很好地创建位图。但是,当我尝试设置选项然后使用该选项对象获取位图时,options对象似乎设置不正确,并且位图为null。请让我知道我在做什么错。感谢您的帮助。
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对象只能用于生成位图一次。当我删除该行并尝试时,它工作正常。花了我几个小时来解决这个问题,希望对您有所帮助。