surfaceChanged()内的Bitmap.createBitmap()抛出IllegalArgumentException

时间:2017-01-28 17:25:41

标签: android android-view surfaceview android-bitmap

我从Play控制台收到以下崩溃报告:

Fatal Exception: java.lang.IllegalArgumentException: bitmap size exceeds 32 bits
       at android.graphics.Bitmap.nativeCreate(Bitmap.java)
       at android.graphics.Bitmap.createBitmap(Bitmap.java:942)
       at android.graphics.Bitmap.createBitmap(Bitmap.java:913)
       at android.graphics.Bitmap.createBitmap(Bitmap.java:880)
       at com.androidapp.test.Surface.surfaceChanged(Surface.java:145)
       at android.view.SurfaceView.updateWindow(SurfaceView.java:730)
       at android.view.SurfaceView.setFrame(SurfaceView.java:378)
       at android.view.View.layout(View.java:16935)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
       at android.view.View.layout(View.java:16939)
       at android.view.ViewGroup.layout(ViewGroup.java:5409)
       at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1077)
       at android.view.View.layout(View.java:16939)
       at android.view.ViewGroup.layout(ViewGroup.java:5409)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
       at android.view.View.layout(View.java:16939)
       at android.view.ViewGroup.layout(ViewGroup.java:5409)
       at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1702)
       at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1556)
       at android.widget.LinearLayout.onLayout(LinearLayout.java:1465)
       at android.view.View.layout(View.java:16939)
       at android.view.ViewGroup.layout(ViewGroup.java:5409)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
       at android.view.View.layout(View.java:16939)
       at android.view.ViewGroup.layout(ViewGroup.java:5409)
       at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1702)
       at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1556)
       at android.widget.LinearLayout.onLayout(LinearLayout.java:1465)
       at android.view.View.layout(View.java:16939)
       at android.view.ViewGroup.layout(ViewGroup.java:5409)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
       at android.view.View.layout(View.java:16939)
       at android.view.ViewGroup.layout(ViewGroup.java:5409)
       at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2464)
       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2167)
       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1301)
       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7016)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:777)
       at android.view.Choreographer.doCallbacks(Choreographer.java:590)
       at android.view.Choreographer.doFrame(Choreographer.java:560)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:763)
       at android.os.Handler.handleCallback(Handler.java:739)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:145)
       at android.app.ActivityThread.main(ActivityThread.java:6946)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

这太奇怪了,因为以下问题仅在某些特定设备上发生。特别是三星SM-J200G & Vivo V3

这里的代码是surfaceCreated()方法中的代码,

@Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
        bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        bitmap.eraseColor(Color.TRANSPARENT);

        drawCanvas.setBitmap(bitmap);

        if (initialBitmap != null) {
            drawCanvas.drawBitmap(initialBitmap, 0, 0, null);
        }
    }

为了清除这种混淆,我创建了一个空位图,而不是从文件中创建,这引用了以下问题,

Mysterious stacktrace in Android developer console (bitmap size exceeds 32bits)

有关可能原因的任何想法?

0 个答案:

没有答案