【Android图像处理】图像处理之-极速奔驰滤镜

来源:互联网 发布:m48a2数据 编辑:程序博客网 时间:2024/05/21 11:34

极速奔驰,顾名思义就是模拟物体在高速运动的时的状态,但是处理后的图片看上去会比较容易让人头晕。

具体代码如下:

//极速奔驰public static Bitmap ZoomBlur(Bitmap bitmap){int w = bitmap.getWidth();int h = bitmap.getHeight();Bitmap result = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565);int m_fcx = (int)(w * 32768) ;int m_fcy = (int)(h * 32768) ;final int ta = 255;int r,g,b,color;int[] oldPx = new int[w * h];int[] newPx = new int[w * h];bitmap.getPixels(oldPx, 0, w, 0, 0, w, h);for(int x = 0 ; x < w ; x++){for(int y = 0 ; y < h ; y++){//得到当前点的r,g,b值int sa = 0;color = oldPx[x * h + y];r = Color.red(color) * ta;g = Color.green(color) * ta;b = Color.blue(color) * ta;sa += ta;int   fx = (x * 65536) - m_fcx ;int   fy = (y * 65536) - m_fcy ;final int RADIUS_LENGTH = 64;for (int i = 0 ; i < RADIUS_LENGTH ; i++){fx = fx - (fx / 16) * 30 / 1024 ;fy = fy - (fy / 16) * 30 / 1024 ;int   u = (fx + m_fcx + 32768) / 65536 ;int   v = (fy + m_fcy + 32768) / 65536 ;if (u>=0 && u<w && v>=0 && v<h){color = oldPx[u * h + v];r += Color.red(color) * ta ;g += Color.green(color) * ta ;b += Color.blue(color) * ta ;sa += ta ;}}r = r / sa;g = g / sa;b = b / sa;//检查颜色值是否超出范围if(r > 255){r = 255;}else if(r < 0){r = 0;}if(g > 255){g = 255;}else if(g < 0){g = 0;}if(b > 255){b = 255;}else if(b < 0){b = 0;}newPx[x * h + y] = Color.rgb(r, g, b);}}result.setPixels(newPx, 0, w, 0, 0, w, h);return result;}
效果如下:

                       效果图                                                                原图


在使用本算法处理图片的时候最好将图片截取成宽高相等的图片。

1 0
原创粉丝点击