java - 在 Android 中将 RGB 值数组转换为图像

标签 java android rgb android-bitmap

我已通过 BitmapFactory.decodeStream 和此代码将 JPEG 图像转换为 RGB 颜色值数组:

picw = selectedImage.getWidth();
pich = selectedImage.getHeight();

int[] pix = new int[picw * pich];

selectedImage.getPixels(pix, 0, picw, 0, 0, picw, pich);
int R, G, B;

for (int y = 0; y < pich; y++) {
        for (int x = 0; x < picw; x++) {
            int index = y * picw + x;
            R = (pix[index] >> 16) & 0xff;
            G = (pix[index] >> 8) & 0xff;
            B = pix[index] & 0xff;
            pix[index] = (R << 16) | (G << 8) | B;
        }
    }

现在,如何将这个数组转换回图像?

最佳答案

你可以使用静态方法Bitmap.createBitmap .例如

Bitmap bmp = Bitmap.createBitmap(pix, picw, pich, Bitmap.Config.ARGB_8888)

关于java - 在 Android 中将 RGB 值数组转换为图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34466225/

相关文章:

java - 如何修剪字符串的特定部分的这一行

java - maven weblogic 安全 jar

Java 项目 : should . 类路径 .project 文件被提交到存储库?

android - 注销新的 Google Cloud Messaging

c++ - 从ppm文件读取RGB值,并使用结构将其存储到称为 “Image”的2d数组中(动态数组)

java - 开始无流程游戏开发

android - 无法创建 Android 虚拟设备

onListItemClick 中的 Android SwitchCase

colors - 平均定义线性渐变的两种颜色的最佳方法是什么?

image - 从RGB到YCbCr的转换公式