Android图像处理——积木效果
积木效果原理:
对图像中的各个像素点加大分像素的颜色值
px = (r + g + b) / 3;
int px = (r + g + b) / 3;
if (px > 127) {
px = 255;
} else {
px = 0;
}
代码:
/**
* 积木效果:
* 对图像中的像素点着重(即加大分像素的颜色值)着色
* @param bitmap
* @return
*/
public static Bitmap handleBlockEffect(Bitmap bitmap) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int color, a, r, g, b;
Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
int[] oldPx = new int[width * height];
int[] newPx = new int[width * height];
bitmap.getPixels(oldPx, 0, width, 0, 0, width, height);
for (int i = 0; i < oldPx.length; i++) {
color = oldPx[i];
a = Color.alpha(color);
r = Color.red(color);
g = Color.green(color);
b = Color.blue(color);
int px = (r + g + b) / 3;
if (px > 127) {
px = 255;
} else {
px = 0;
}
r = g = b = px;
newPx[i] = Color.argb(a, r, g, b);
}
bmp.setPixels(newPx, 0, width, 0, 0, width, height);
return bmp;
}
效果如下图:
原图:
效果图: