简体   繁体   English

更改图像png的颜色在Android中的多个像素?

[英]change color of image png for multiple pixel in android?

I have an image for my app, I need to change every wall color in the imageview wall color like living room ... like this image 我的应用程序有一个图像,我需要更改imageview墙壁颜色中的每种墙壁颜色,例如客厅……像这张图像

how to change image colors for highlights in android? 如何在Android中更改突出显示的图像颜色?

You have to grab the pixel RGB value at certain points in your imageView Bitmap. 您必须在imageView位图中的某些点获取像素RGB值。 Then from there you can SetPixel, and account for alpha and then flip the pixels in which you want to alter the value. 然后可以从那里设置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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM