ITPub博客

首页 > IT职业 > IT图书 > android 图片特效处理 怀旧风格

android 图片特效处理 怀旧风格

IT图书 作者:populace 时间:2021-09-09 10:07:42 0 删除 编辑

处理前

图片描述

处理后

图片描述

上代码

/** 
     * 怀旧效果
     * @param bmp 
     * @return 
     */  
    private Bitmap oldRemeber(Bitmap bmp)  
    {  
        // 速度测试  
        long start = System.currentTimeMillis();  
        int width = bmp.getWidth();  
        int height = bmp.getHeight();  
        Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);  
        int pixColor = 0;  
        int pixR = 0;  
        int pixG = 0;  
        int pixB = 0;  
        int newR = 0;  
        int newG = 0;  
        int newB = 0;  
        int[] pixels = new int[width * height];  
        bmp.getPixels(pixels, 0, width, 0, 0, width, height);  
        for (int i = 0; i < height; i++)  
        {  
            for (int k = 0; k < width; k++)  
            {  
                pixColor = pixels[width * i + k];  
                pixR = Color.red(pixColor);  
                pixG = Color.green(pixColor);  
                pixB = Color.blue(pixColor);  
                newR = (int) (0.393 * pixR + 0.769 * pixG + 0.189 * pixB);  
                newG = (int) (0.349 * pixR + 0.686 * pixG + 0.168 * pixB);  
                newB = (int) (0.272 * pixR + 0.534 * pixG + 0.131 * pixB);  
                int newColor = Color.argb(255, newR > 255 ? 255 : newR, newG > 255 ? 255 : newG, newB > 255 ? 255 : newB);  
                pixels[width * i + k] = newColor;  
            }  
        }  
          
        bitmap.setPixels(pixels, 0, width, 0, 0, width, height);  
        long end = System.currentTimeMillis();  
        Log.d("may", "used time="+(end - start));  
        return bitmap;  
    }

转自 http://blog.csdn.net/zhang31jian/article/details/16821123

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3026/viewspace-2816960/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 数据挖掘 python 1
请登录后发表评论 登录
全部评论

注册时间:2019-08-30

  • 博文量
    74
  • 访问量
    491