android - 在android中为多个像素更改图像png的颜色?

标签 android

我的应用程序有一张图片,我需要更改 imageview 墙壁颜色中的每一个墙壁颜色,例如客厅......就像这张图片

how to change image colors for highlights in android?

最佳答案

您必须获取 imageView 位图中特定点的像素 RGB 值。然后您可以从那里设置像素并考虑 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);

关于android - 在android中为多个像素更改图像png的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29353976/

相关文章:

Android浏览器历史URI?

android - 使用 Mockito.verify() 时,不只是检查是否在模拟对象上调用了该函数,而是调用来自真实对象的方法

android - 如何在 android 应用程序中使用大型数据库(Sqlite 超过 100 MB)?

java - Junit/Mockito - 等待方法执行

android - 是否可以减少扫描 BLE 设备的时间?

java - 如何创建一个带有图标替换另一个 apk 的 apk

android - 从 Android 调用 Google Cloud Endpoints API 时出现错误 413(请求实体太大)

Android 如何验证 ACRA 崩溃日志安装成功

java - Android Webview 内容在使用透明背景时重叠

android - Dagger 和 mvp - 演示者是否应该使用 dagger 进行注入(inject)