IllegalArgumentException:容量错误

时间:2017-02-12 22:59:46

标签: android illegalargumentexception capacity

在实现将图像转换为灰度的方法后,我收到了这个奇怪的错误:

public Bitmap toGrayscale(Bitmap bmpOriginal)
{
    int width, height;
    height = bmpOriginal.getHeight();
    width = bmpOriginal.getWidth();
    Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
    Canvas c = new Canvas(bmpGrayscale);
    Paint paint = new Paint();
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0);
    ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
    paint.setColorFilter(f);
    c.drawBitmap(bmpOriginal, 0, 0, paint);
    bmpOriginal.recycle();
    return bmpGrayscale;
}

错误:

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: mantas.spr_demo, PID: 20853
                  java.lang.IllegalArgumentException: Capacity: -2147483647
                      at java.util.HashMap.<init>(HashMap.java:140)
                      at java.util.HashMap.<init>(HashMap.java:174)
                      at java.util.LinkedHashMap.<init>(LinkedHashMap.java:119)
                      at java.util.LinkedHashMap.<init>(LinkedHashMap.java:97)
                      at java.util.LinkedHashMap.<init>(LinkedHashMap.java:81)
                      at com.jjoe64.graphview.GridLabelRenderer.adjustVertical(GridLabelRenderer.java:768)
                      at com.jjoe64.graphview.GridLabelRenderer.adjustSteps(GridLabelRenderer.java:932)
                      at com.jjoe64.graphview.GridLabelRenderer.draw(GridLabelRenderer.java:1067)
                      at com.jjoe64.graphview.GraphView.drawGraphElements(GraphView.java:299)
                      at com.jjoe64.graphview.GridLabelRenderer.draw(GridLabelRenderer.java:1062)
                      at com.jjoe64.graphview.GraphView.drawGraphElements(GraphView.java:299)
                      at com.jjoe64.graphview.GraphView.onDraw(GraphView.java:323)
                      at android.view.View.draw(View.java:16302)
                      at android.view.View.updateDisplayListIfDirty(View.java:15284)
                      at android.view.View.draw(View.java:16072)
                      at android.view.ViewGroup.drawChild(ViewGroup.java:3622)
                      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3409)
                      at android.view.View.draw(View.java:16305)
                      at android.view.View.updateDisplayListIfDirty(View.java:15284)
                      at android.view.View.draw(View.java:16072)
                      at android.view.ViewGroup.drawChild(ViewGroup.java:3622)
                      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3409)
                      at android.view.View.updateDisplayListIfDirty(View.java:15279)
                      at android.view.View.draw(View.java:16072)
                      at android.view.ViewGroup.drawChild(ViewGroup.java:3622)
                      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3409)
                      at android.view.View.updateDisplayListIfDirty(View.java:15279)
                      at android.view.View.draw(View.java:16072)
                      at android.view.ViewGroup.drawChild(ViewGroup.java:3622)
                      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3409)
                      at android.view.View.draw(View.java:16305)
                      at com.android.internal.policy.PhoneWindow$DecorView.draw(PhoneWindow.java:2760)
                      at android.view.View.updateDisplayListIfDirty(View.java:15284)
                      at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:295)
                      at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:301)
                      at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:345)
                      at android.view.ViewRootImpl.draw(ViewRootImpl.java:2686)
                      at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2495)
                      at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2120)
                      at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1138)
                      at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6227)
                      at android.view.Choreographer$CallbackRecord.run(Choreographer.java:884)
                      at android.view.Choreographer.doCallbacks(Choreographer.java:696)
                      at android.view.Choreographer.doFrame(Choreographer.java:631)
                      at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:870)
                      at android.os.Handler.handleCallback(Handler.java:743)
                      at android.os.Handler.dispatchMessage(Handler.java:95)
                      at android.os.Looper.loop(Looper.java:150)
                      at android.app.ActivityThread.main(ActivityThread.java:5546)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)

应用程序在没有 toGrayscale 方法的情况下正常工作。但我真的需要它。试图添加recycle();代码中到处都是方法,以防止超出内存,但它无法正常工作。我无法回收 bmpGrayscale ,因为我需要返回。知道什么可能是错的吗?

0 个答案:

没有答案