1

I'm having trouble while converting a bitmap from RGB to Grayscale. Before conversion, the image had a 2102 x 932 pixels and 300 dpi. After the conversion, the image size remains the same but the resolution scaled down to 96dpi. The code to convert to grayscale I'm using is from this stackoverflow answer by leparlon:

public Bitmap toGrayscale(Bitmap bmpOriginal){        
    int width, height;
    height = bmpOriginal.getHeight();
    width = bmpOriginal.getWidth();    

    Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    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);
    return bmpGrayscale;
}

Some of you have faced this kind of issue?

Community
  • 1
  • 1

0 Answers0