我在将位图从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;
}
你们有些人遇到过这种问题吗?