【问题标题】:android noise effect on bitmap位图上的android噪声效果
【发布时间】:2013-05-17 10:38:51
【问题描述】:

我正在编写一些函数来在位图上添加噪声效果。我发现了类似的问题:Add noise effect to a drawing

位图输出位图 = 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);

我应该如何添加滤色器才能获得这样的结果?你能提供简单的代码吗?

【问题讨论】:

    标签: android image bitmap noise


    【解决方案1】:

    我建议使用此代码。

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

    欢迎。

    【讨论】:

    • 如何增加/减少这种跳蚤效果的强度?
    猜你喜欢
    • 1970-01-01
    • 2013-10-14
    • 1970-01-01
    • 2013-10-06
    • 2018-09-08
    • 2019-01-04
    • 2013-02-13
    • 2011-01-27
    相关资源
    最近更新 更多