由于内存不足,黑白位图有时会崩溃

时间:2014-03-08 15:26:42

标签: android bitmap out-of-memory

我有这个功能将位图转换为黑白。

public static Bitmap convertColorIntoBlackAndWhiteImage(Bitmap orginalBitmap) {
    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.setSaturation(0);

    ColorMatrixColorFilter colorMatrixFilter = new ColorMatrixColorFilter(colorMatrix);
    Bitmap blackAndWhiteBitmap = orginalBitmap.copy(Bitmap.Config.ARGB_8888, true);

    Paint paint = new Paint();
    paint.setColorFilter(colorMatrixFilter);

    Canvas canvas = new Canvas(blackAndWhiteBitmap);
    canvas.drawBitmap(blackAndWhiteBitmap, 0, 0, paint);

    return blackAndWhiteBitmap;
}

在某些设备中,有时它会以

崩溃
W/System.err(16049): java.lang.OutOfMemoryError
W/System.err(16049):    at android.graphics.Bitmap.nativeCopy(Native Method)
W/System.err(16049):    at android.graphics.Bitmap.copy(Bitmap.java:479)

有什么想法吗? :P

0 个答案:

没有答案