改变android中多个像素的图像png的颜色?

时间:2015-03-30 18:53:21

标签: android

我有我的应用程序的图像,我需要更改imageview墙壁颜色的每个墙壁颜色,如客厅...像这样的图像

how to change image colors for highlights in android?

1 个答案:

答案 0 :(得分:0)

您必须在imageView位图中的某些点抓取像素RGB值。然后从那里你可以SetPixel,并考虑alpha,然后翻转你想要改变值的像素。

        BitmapFactory.Options opt = new BitmapFactory.Options();
        opt.inMutable = true;
        opt.inScaled = false;

        Bitmap ico = BitmapFactory.decodeResource(context.getResources(), R.drawable.colored_wall_pic, opt);

        int color = 15132390 & 0x00FFFFFF; //15132390 is like whiteish gray
        for (int x = 0; x < w; x++) {
            for (int y = 0; y < h; y++) {
                int alpha = ico.getPixel(x, y) & 0xFF000000;
                if (alpha != 0) {
                    ico.setPixel(x, y, color | alpha);
                }
            }
        }

        Bitmap icon = Bitmap.createBitmap(ico.getWidth(), ico.getHeight(), ico.getConfig());

        // overlay transparent mutable Bitmap on transparent background
        Canvas canvas = new Canvas(icon);
        canvas.drawBitmap(ico, 0, 0, null);