I am trying to show a JPEG to a ANativeWindow with the Android NDK. I am getting the ANativeWindow*
by doing:
我试图用Android NDK向一个ANativeWindow显示一个JPEG。我通过以下方式获取ANativeWindow *:
_window = ANativeWindow_fromSurface(env, surface)
I am loading the jpeg, with libjpeg-turbo, by doing:
我正在使用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);
}
My Question is, how to show the decoded jpeg on the surface ? I am currently doing this:
我的问题是,如何在表面上显示解码的jpeg?我目前正在这样做:
ANativeWindow_Buffer surface_buffer;
if (ANativeWindow_lock(_window, &surface_buffer, NULL) == 0) {
memcpy(surface_buffer.bits, _buffer, _bufferSize);
ANativeWindow_unlockAndPost(_window);
}
But the result (see below) is not what I was expecting. What should I do before sending the buffer to the surface ?
但结果(见下文)并不是我所期待的。在将缓冲区发送到表面之前,我该怎么办?
Thanks
1 个解决方案
#1
2
Just need to set ANativeWindow's format with ANativeWindow_setBuffersGeometry(_window, 0, 0, WINDOW_FORMAT_RGBA_8888)
. And then use TJPF_RGBA
format instead of TJPF_ARGB
.
只需要使用ANativeWindow_setBuffersGeometry(_window,0,0,WINDOW_FORMAT_RGBA_8888)设置ANativeWindow的格式。然后使用TJPF_RGBA格式而不是TJPF_ARGB。
#1
2
Just need to set ANativeWindow's format with ANativeWindow_setBuffersGeometry(_window, 0, 0, WINDOW_FORMAT_RGBA_8888)
. And then use TJPF_RGBA
format instead of TJPF_ARGB
.
只需要使用ANativeWindow_setBuffersGeometry(_window,0,0,WINDOW_FORMAT_RGBA_8888)设置ANativeWindow的格式。然后使用TJPF_RGBA格式而不是TJPF_ARGB。