java.lang.IllegalArgumentException:位图大小超过32位

时间:2015-11-20 22:31:26

标签: java android bitmap

我在Android上收到用户报告的一些崩溃信息。它们似乎只发生在平板电脑而不是手机上,但我可能错了。以下是我遇到的Android崩溃的两个错误日志

java.lang.RuntimeException: Unable to resume activity {com.pa.modelreleaseapp/com.pa.modelreleaseapp.EditActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=3, result=-1, data=Intent { (has extras) }} to activity {com.pa.modelreleaseapp/com.pa.modelreleaseapp.EditActivity}: java.lang.IllegalArgumentException: bitmap size exceeds 32 bits
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3509)
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3540)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2860)
    at android.app.ActivityThread.access$900(ActivityThread.java:181)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1474)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:6117)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=3, result=-1, data=Intent { (has extras) }} to activity {com.pa.modelreleaseapp/com.pa.modelreleaseapp.EditActivity}: java.lang.IllegalArgumentException: bitmap size exceeds 32 bits
    at android.app.ActivityThread.deliverResults(ActivityThread.java:4173)
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3495)
    ... 11 more
Caused by: java.lang.IllegalArgumentException: bitmap size exceeds 32 bits
    at android.graphics.Bitmap.nativeCreate(Native Method)
    at android.graphics.Bitmap.createBitmap(Bitmap.java:939)
    at android.graphics.Bitmap.createBitmap(Bitmap.java:912)
    at android.graphics.Bitmap.createBitmap(Bitmap.java:843)
    at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:719)
    at com.pa.modelreleaseapp.EditActivity.onActivityResult(EditActivity.java:677)
    at android.app.Activity.dispatchActivityResult(Activity.java:6632)
    at android.app.ActivityThread.deliverResults(ActivityThread.java:4169)
    ... 12 more

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=3, result=-1, data=Intent { (has extras) }} to activity {com.pa.modelreleaseapp/com.pa.modelreleaseapp.EditActivity}: java.lang.IllegalArgumentException: bitmap size exceeds 32bits
    at android.app.ActivityThread.deliverResults(ActivityThread.java:3577)
    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3620)
    at android.app.ActivityThread.access$1400(ActivityThread.java:169)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1325)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5479)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: bitmap size exceeds 32bits
    at android.graphics.Bitmap.nativeCreate(Native Method)
    at android.graphics.Bitmap.createBitmap(Bitmap.java:928)
    at android.graphics.Bitmap.createBitmap(Bitmap.java:901)
    at android.graphics.Bitmap.createBitmap(Bitmap.java:833)
    at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:709)
    at com.pa.modelreleaseapp.EditActivity.onActivityResult(EditActivity.java:677)
    at android.app.Activity.dispatchActivityResult(Activity.java:5643)
    at android.app.ActivityThread.deliverResults(ActivityThread.java:3573)
    ... 11 more

这是我的文件代码

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent     data) {
super.onActivityResult(requestCode, resultCode, data);
///SGI_ADD
if (requestCode == REQUEST_SIGN)
{
    Bundle bundle = new Bundle();
    bundle = data.getExtras();
    Boolean bSignature = bundle.getBoolean("guardian");
    String strFile = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getPath();
    if (bSignature )
    {
        strFile = strFile + "/"+"releasedContracts"+"/"+"signature_guardian.png";
    }
    else{
        strFile = strFile + "/"+"releasedContracts"+"/"+"signature.png";
    }
    ////////////////
    BitmapFactory.Options options1 = new BitmapFactory.Options();
    options1.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(strFile, options1);
    final int REQUIRED_SIZE1 = 200;
    int scale1 = 1;
    options1.inSampleSize = scale1;
    options1.inJustDecodeBounds = false;
    ///////////////
    Bitmap bitmap = BitmapFactory.decodeFile(strFile,options1);
    int w1 = bitmap.getWidth();
    float scale_w1 = w1/REQUIRED_SIZE1;
    int h1 = (int)(bitmap.getHeight()/scale_w1);
    Bitmap resized1 = Bitmap.createScaledBitmap(bitmap, REQUIRED_SIZE1, h1, true);

    m_signBitmap = resized1;
    if (bSignature )
    {
        imgSignature_guardian.setImageBitmap(resized1);
    }
    else{
        imgSignature.setImageBitmap(resized1);
    }
}

任何想法?

2 个答案:

答案 0 :(得分:0)

我有类似的问题,我不知道最好的'回答。我已经考虑过将位图写入临时数据库,然后在下一个活动中检索,但我不知道这是否会影响性能。这是我在尝试发送位图之前所做的事情。此处还有一对Google links处理位图。

    //Compress the Bitmap if its over an arbitrary size that probably could crash at a lower count.
    if (byteArray.length > 524288){
        for (int i = 95; (byteArray.length > 524288 && i >= 20); i = i - 5) {
            stream.reset();
            Log.d(packagename, "BEFORE byteLength - Compression: " + i + " - " + byteArray.length + " stream " + stream.size());
            bitmap.compress(Bitmap.CompressFormat.JPEG, i, stream);
            byteArray = stream.toByteArray();
            Log.d(packagename, "AFTER byteLength - Compression: " + i + " - " + byteArray.length + " stream " + stream.size());
        }
    }

答案 1 :(得分:0)

我通过缩放位图来解决它,我遇到了同样的问题 xiaomi mi 移动它总是用来崩溃...试一试

final int BORDER_WIDTH = 10;
final int BORDER_COLOR = Color.YELLOW;
Bitmap res = Bitmap.createBitmap(bmp.getWidth() + 2 *   BORDER_WIDTH,bmp.getHeight() + 2 * BORDER_WIDTH,bmp.getConfig());
Bitmap bmp = BitmapFactory.decodeFile(path, options);
Canvas .drawRect(0, 0, res.getWidth(), res.getHeight(), p);
float viewWidth = (float) res.getWidth();
float viewHeight =(float) res.getHeight();
float ratiowidth = viewWidth / (float) res.getWidth();
float ratioheight = viewHeight / (float) res.getHeight();
Matrix mat = new Matrix();
mat.postScale(ratiowidth, ratioheight);
Bitmap bMapRotate = Bitmap.createBitmap(res, 0,0,res.getWidth(),res.getHeight(), mat, true);