【Android图像处理】lomo滤镜(效果)

来源:互联网 发布:select算法 编辑:程序博客网 时间:2024/05/18 01:09

前面说到过Android矩阵处理,每个矩阵都对应一个效果。

lomo效果的矩阵如下:

1.7 0.1 0.1 -73.1
0 1.7 0.1 -73.1
0 0.1 1.6 -73.1

那具体的算法如下:

//lomopublic static Bitmap Lomo1(Bitmap bitmap){int w = bitmap.getWidth();int h = bitmap.getHeight();Bitmap resultBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565);int color = 0;int a,r,g,b,r1,g1,b1;int[] oldPx = new int[w * h];int[] newPx = new int[w * h];bitmap.getPixels(oldPx, 0, w, 0, 0, w, h);for(int i = 0; i < w * h; i++){color = oldPx[i];r = Color.red(color);g = Color.green(color);b = Color.blue(color);a = Color.alpha(color);r1 = (int) (1.7 * r + 0.1 * g + 0.1 * b - 73.1);g1 = (int) (0 * r + 1.7 * g + 0.1 * b - 73.1);b1 = (int) (0 * r + 0.1 * g + 1.6 * b - 73.1);//检查各通道值是否超出范围if(r1 > 255){r1 = 255;}if(g1 > 255){g1 = 255;}if(b1 > 255){b1 = 255;}newPx[i] = Color.argb(a, r1, g1, b1);}resultBitmap.setPixels(newPx, 0, w, 0, 0, w, h);return resultBitmap;}
其效果如下:


原图如下:


5 0