本文介绍了位图的android噪声的影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一些功能上添加位图噪声的影响。我发现了类似的问题:添加隔音效果到绘图

I am writing some function to add noise effect on bitmap. I found similar question: Add noise effect to a drawing

位图outputBitmap = Bitmap.createBitmap(bitmap.getWidth(),bitmap.getHeight(),Bitmap.Config.ARGB_8888);

Bitmap outputBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);

    BitmapShader shader = new BitmapShader (bitmap,  TileMode.REPEAT, TileMode.REPEAT);

    Paint paint = new Paint();
    paint.setShader(shader);

    Canvas c = new Canvas(outputBitmap);
    c.drawBitmap(bitmap, 0, 0, paint);

我应该如何添加颜色过滤器得到这样的结果?你能提供somple code?

How should i add color filter to get such a result? Could you provide somple code?

推荐答案

我建议使用这种code。

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;
}

的欢迎。

这篇关于位图的android噪声的影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 21:27