获取图片时:
assert(AIMAGE_FORMAT_JPEG == src_format, "Failed to get format");
AImage_getHeight(image, &height);
AImage_getWidth(image, &width);
AImage_getPlaneData(image, 0, &pixel, &y_len);
AImage_getPlaneRowStride(image, 0, &stride);
AImage_getPlanePixelStride(image, 0, &pixel_stride);
请注意,对于该格式,最后 2 个命令返回 AMEDIA_ERROR_UNSUPPORTED
- 参见 docs .
现在写入缓冲区:
uint8_t *out = buf.data;
for (int y = 0; y < height; y++) {
const uint8_t *pY = pixel + width*3*y;
for (int x = 0; x < width; x++) {
out[x*3 + 0] = pY[x*3 + 0];
out[x*3 + 1] = pY[x*3 + 1];
out[x*3 + 2] = pY[x*3 + 2];
}
out += width*3;
}
应用程序在启动后很快崩溃。 logcat
不会输出对我有意义的内容 - 至少不可读。关于如何处理这个问题有什么想法吗?
最佳答案
getPlaneData()对于 JPEG 为您提供未解码的缓冲区。可以看到返回的尺寸远小于width*height*3
。
关于android - 获取 AIMAGE_FORMAT_JPEG 图像失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43833989/