zoukankan      html  css  js  c++  java
  • 怀旧效果函数

    // 怀旧效果函数
    public static Bitmap changeToOld(Bitmap bitmap) {

    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Log.i("OldFilter", "width=" + width + "; height=" + height);
    Bitmap returnBitmap = 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];
    bitmap.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;
    }
    }

    returnBitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return returnBitmap;
    }

  • 相关阅读:
    Java统计程序运行时间(转)
    有符号定点数的表示方法
    移位运算符
    索引
    self与super的区别(转)
    Java经典题型(未完成)
    ObjectiveC 的 self 和 super 详解
    边界计算与不对称边界
    各种排序总结
    运算符的优先级
  • 原文地址:https://www.cnblogs.com/clarence/p/3837480.html
Copyright © 2011-2022 走看看