10英寸平板电脑上的Android BitmapRegionDecoder encodeRegion NullPointerException

And*_*rli 2 android bitmap nullpointerexception

在我的Android应用中,我使用以下代码:

BitmapRegionDecoder decoder;
...
decoder = BitmapRegionDecoder.newInstance(myStream, false);
...
int width = -1, height = -1, left = -1, top = -1;
...
Log.d("GDA", left + " " + top + " " + width + " " + height);
Rect re = new Rect(left, top, width, height);
Log.d("GDA", re.toString());
if(decoder != null)
    region = decoder.decodeRegion(re, null);
Run Code Online (Sandbox Code Playgroud)

一切都可以在智能手机和7英寸平板电脑上正常运行,但在10英寸平板电脑上(我在Samsung GT10.1和Acer A501上进行了测试),我收到此错误消息:

1152 1728 2304 2592
Rect(1152, 1728 - 2304, 2592)
java.lang.NullPointerException
    at android.graphics.BitmapRegionDecoder.decodeRegion(BitmapRegionDecoder.java:399)
Run Code Online (Sandbox Code Playgroud)

我找不到解决方案。有人遇到过同样的问题吗?有什么建议么?

小智 5

解:

不要使用“ region = coder.decodeRegion(re,null);”,例如:

BitmapFactory.Options options = new BitmapFactory.Options();
region = decoder.decodeRegion(re, options);
Run Code Online (Sandbox Code Playgroud)

工作正常,已检查Galaxy Tab 10.1 Android 4.0.x