【问题标题】:java.lang.IllegalArgumentException: bitmap size exceeds 32 bitsjava.lang.IllegalArgumentException:位图大小超过 32 位
【发布时间】:2016-04-27 20:22:28
【问题描述】:

我收到一些用户在 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);
    }
}

有什么想法吗?

【问题讨论】:

    标签: java android bitmap


    【解决方案1】:

    我也遇到过类似的问题,我不知道“最佳”答案。我曾考虑将位图写入临时数据库,然后在下一个活动中检索,但我不知道这是否会影响性能。这是我在尝试发送位图之前正在做的事情。这里还有一对Googlelinks处理位图。

        //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());
            }
        }
    

    【讨论】:

      【解决方案2】:

      我通过缩放位图解决了这个问题,小米米手机也遇到了同样的问题,它总是崩溃...试试看

      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);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多