我正在尝试使用 Android NDK 向 ANativeWindow 显示 JPEG。我正在ANativeWindow*
这样做:
_window = ANativeWindow_fromSurface(env, surface)
我正在使用 libjpeg-turbo 加载 jpeg,方法是:
if (tjDecompressHeader2(tj, jpeg, jpegSize, &width, &height, &subsamp) == 0) {
int format = TJPF_ARGB;
int pitch = _windowWidth * tjPixelSize[format];
_bufferSize = pitch * _windowHeight;
_buffer = realloc(_buffer, _bufferSize);
tjDecompress2(tj, jpeg, jpegSize, _buffer, _windowWidth, pitch, _windowHeight, format, 0);
}
我的问题是,如何在表面上显示解码的 jpeg?我目前正在这样做:
ANativeWindow_Buffer surface_buffer;
if (ANativeWindow_lock(_window, &surface_buffer, NULL) == 0) {
memcpy(surface_buffer.bits, _buffer, _bufferSize);
ANativeWindow_unlockAndPost(_window);
}
但结果(见下文)不是我所期望的。在将缓冲区发送到表面之前我应该做什么?
谢谢