Android图像处理——底片效果
底片效果原理:
或得每一个点的像素值,取反后的颜色值设置到对应的点上
r = 255 - r;
g = 255 - g;
b = 255 - b;
核心代码:
/**
* 底片效果
* @param bitmap
* @return
*/
public static Bitmap handleInvertEffect(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);
r = 255 - r;
g = 255 - g;
b = 255 - b;
newPx[i] = Color.argb(a, r, g, b);
}
bmp.setPixels(newPx, 0, width, 0, 0, width, height);
return bmp;
}
效果图如下:
原图:
效果图: