本文介绍了如何改变图像色彩在Android的亮点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的应用程序的图像,我需要更改的ImageView每面墙上的颜色。像这样的图片:

I have an image for my app, I need to change every wall color in the imageview. Like this image:

推荐答案

您必须抢在你的ImageView位图在某些点的像素RGB值。然后从那里你可以的setPixel,并占阿尔法,然后翻转中,你要改变的值的像素。

You have to grab the pixel RGB value at certain points in your imageView Bitmap. Then from there you can SetPixel, and account for alpha and then flip the pixels in which you want to alter the value.

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

这篇关于如何改变图像色彩在Android的亮点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 21:59