zoukankan      html  css  js  c++  java
  • 光照效果函数

    // 光照效果函数
    public static Bitmap changeToLight(Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();

    int pixColor = 0;
    int R = 0;
    int G = 0;
    int B = 0;

    int centerX = width /3;
    int centerY = height / 3;
    int radius = Math.min(centerX, centerY);

    int strength = 150; // 光照强度 100~150
    int[] pixels = new int[width * height];
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);

    int pos = 0, distance, result;
    for (int y = 1; y < height - 1; y++) {
    for (int x = 1; x < width - 1; x++) {
    pos = y * width + x;
    pixColor = pixels[pos];

    R = Color.red(pixColor);
    G = Color.green(pixColor);
    B = Color.blue(pixColor);

    // 计算当前点到光照中心的距离,平面座标系中求两点之间的距离
    distance = (centerY - y)*(centerY - y) + (centerX - x)*(centerX-x);
    if (distance < radius * radius) {
    // 按照距离大小计算增加的光照值
    result = (int) (strength * (1.0 - Math.sqrt(distance)/radius));
    R += result;
    G += result;
    B += result;

    R = Math.min(255, Math.max(0, R));
    G = Math.min(255, Math.max(0, G));
    B = Math.min(255, Math.max(0, B));

    pixels[pos] = Color.rgb(R, G, B);
    }
    }
    }

    Bitmap returnBitmap = Bitmap.createBitmap(width, height,
    Bitmap.Config.RGB_565);
    returnBitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return returnBitmap;
    }

  • 相关阅读:
    jvm 更多链接
    JVM 内存初学 (堆(heap)、栈(stack)和方法区(method) )
    python 排序
    python 第K个语法符号
    python conf.ini 文件的使用
    python 表示数字
    window 下安装redis
    python redis相关操作
    python 矩阵乘法
    python 查找两个字符串a,b中的最长公共子串
  • 原文地址:https://www.cnblogs.com/clarence/p/3837468.html
Copyright © 2011-2022 走看看