android noise effect on bitmap

走远了吗. 提交于 2019-12-01 22:08:23

i suggested that use this code.

public static final int COLOR_MIN = 0x00;
public static final int COLOR_MAX = 0xFF;

public static Bitmap applyFleaEffect(Bitmap source) {
    // get image size
    int width = source.getWidth();
    int height = source.getHeight();
    int[] pixels = new int[width * height];
    // get pixel array from source
    source.getPixels(pixels, 0, width, 0, 0, width, height);
    // a random object
    Random random = new Random();

    int index = 0;
    // iteration through pixels
    for(int y = 0; y < height; ++y) {
        for(int x = 0; x < width; ++x) {
            // get current index in 2D-matrix
            index = y * width + x;
            // get random color
            int randColor = Color.rgb(random.nextInt(COLOR_MAX),
                    random.nextInt(COLOR_MAX), random.nextInt(COLOR_MAX));
            // OR
            pixels[index] |= randColor;
        }
    }
    // output bitmap
    Bitmap bmOut = Bitmap.createBitmap(width, height, source.getConfig());
    bmOut.setPixels(pixels, 0, width, 0, 0, width, height);
    return bmOut;
}

welcome.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!