位图转换为灰度后,分辨率正在发生变化

时间:2015-07-28 01:45:13

标签: android bitmap resolution grayscale

我在将位图从RGB转换为灰度时遇到了问题。转换前,图片的 2102 x 932像素 300 dpi 。转换后,图像大小保持不变,但分辨率缩小为 96dpi 。转换为使用灰度的代码来自this stackoverflow answer 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;
}

你们有些人遇到过这种问题吗?

0 个答案:

没有答案