我有这个功能将位图转换为黑白。
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