2

在我的 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);

在智能手机和 7 英寸平板电脑上一切正常,但在 10 英寸平板电脑上(我在三星 GT10.1 和 Acer A501 上测试过)我收到了这个错误:

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

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

4

1 回答 1

6

Solution:

Don't use "region = decoder.decodeRegion(re, null);", use for example:

BitmapFactory.Options options = new BitmapFactory.Options();
region = decoder.decodeRegion(re, options);

It's work, checked for Galaxy Tab 10.1 Android 4.0.x

于 2013-06-29T15:29:21.320 回答