Android图像处理——冰冻特效
冰冻效果算法:
r = (r - g - b) * 3 / 2;
g = (g - r - b) * 3 / 2;
b = (b - r - g) * 3 / 2;
上述公式中,将每个像素点的RGB值分离出来,按照上述公式计算出新的RGB值。
核心代码如下:
/**
* 冰冻效果
* @param bitmap
* @return
*/
public static Bitmap handleCodeEffect(Bitmap bitmap) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int color, a, r, g, b;
int pxR = 0,pxG = 0,pxB = 0;
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(