1

据我了解,每个像素由 4 个字节(a,r,g,b)表示。如何将其存储在 byte[] 数组中,其中大小是图像中的像素数。

以下代码按预期工作(旋转图像)

rotatedData = new byte[data.length];
for (int y = 0; y < height; y++) {
    for (int x = 0; x < width; x++)
        rotatedData[x * height + height - y - 1] = data[x + y * width];
}
data = rotatedData;
int tmp = width; // Here we are swapping, that's the difference to #11
width = height;
height = tmp;
4

1 回答 1

0

如果您正在讨论解码相机预览图像的“NV21”表示,它由一个包含每个像素一个字节的亮度数据的块组成,然后是另一个包含颜色数据的块,每个 2×2 像素块有一个样本。颜色数据的分辨率低于亮度,因为人眼对颜色细节不太敏感。

有关将此格式解码为常规 Android 位图格式 ARGB 像素的示例代码,请参阅此处DecodeNV21的例程。

于 2012-05-21T11:37:27.593 回答