android中如何调整渐变格式位图的亮度?

android中如何调整渐变格式位图的亮度?,android,bitmap,Android,Bitmap,我已经看到了很多关于在android中调整位图亮度的链接和帖子,但是我想用渐变来调整亮度,就像只调整位图中心的亮度一样。有人知道怎么做吗 您可以生成位图并绘制渐变: 然后使用梯度位图中的每个像素,获取亮度并将其传递给调整亮度的函数 看这里 thanx bro寻求帮助…但我已经做了这件事…实际上我的问题是如何调整渐变形式的亮度?例如,亮度应该只从屏幕中心调整…希望你们得到我想要做的…我更新了我的答案,使用位图作为渐变亮度。如果它不符合你的需要,我会删除我的答案。仍然不会改变任何事情…兄弟 publ

我已经看到了很多关于在android中调整位图亮度的链接和帖子,但是我想用渐变来调整亮度,就像只调整位图中心的亮度一样。有人知道怎么做吗

您可以生成位图并绘制渐变:

然后使用梯度位图中的每个像素,获取亮度并将其传递给调整亮度的函数

看这里


thanx bro寻求帮助…但我已经做了这件事…实际上我的问题是如何调整渐变形式的亮度?例如,亮度应该只从屏幕中心调整…希望你们得到我想要做的…我更新了我的答案,使用位图作为渐变亮度。如果它不符合你的需要,我会删除我的答案。仍然不会改变任何事情…兄弟
public Bitmap SetBrightness(Bitmap src, Bitmap gradient) {
    // original image size
    int width = src.getWidth();
    int height = src.getHeight();
    // create output bitmap
    Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());
    // color information
    int A, R, G, B;
    int pixel;

    // scan through all pixels
    for (int x = 0; x < width; ++x) {
        for (int y = 0; y < height; ++y) {
            // get pixel color
            pixel = src.getPixel(x, y);
            A = Color.alpha(pixel);
            R = Color.red(pixel);
            G = Color.green(pixel);
            B = Color.blue(pixel);

            int gradientPixel = gradient.getPixel(x, y);
            int value = getLuminance(gradientPixel);                

            // increase/decrease each channel
            R += value;
            if (R > 255) {
                R = 255;
            }
            else if (R < 0) {
                R = 0;
            }

            G += value;
            if (G > 255) {
                G = 255;
            }
            else if (G < 0) {
                G = 0;
            }

            B += value;
            if (B > 255) {
                B = 255;
            }
            else if (B < 0) {
                B = 0;
            }

            // apply new pixel color to output bitmap
            bmOut.setPixel(x, y, Color.argb(A, R, G, B));
        }
    }

    // return final image
    return bmOut;
}

public int getLuminance(int pixel) {
    int A, R, G, B;
    A = Color.alpha(pixel);
    R = Color.red(pixel);
    G = Color.green(pixel);
    B = Color.blue(pixel);

    return (0.2126 * R) + (0.7152 * G) + (0.0722 * B);
}