1.创建Surface
通过imageReader获取 Window:
核心:
ANativeWindow *nativeWindow;
media_status_t status = AImageReader_getWindow(reader_, &nativeWindow);
ASSERT(status == AMEDIA_OK, "Could not get ANativeWindow");
return nativeWindow;
写成方法:
ANativeWindow *ImageReader::GetNativeWindow(void) {
if (!reader_) return nullptr;
ANativeWindow *nativeWindow;
media_status_t status = AImageReader_getWindow(reader_, &nativeWindow);
ASSERT(status == AMEDIA_OK, "Could not get ANativeWindow");
return nativeWindow;
}
2.获取NativeWindow
iReader = new ImageReader(surfaceWidth, surfaceHeight, AIMAGE_FORMAT_RGBA_8888);
iReaderWindow = iReader->GetNativeWindow();
ANativeWindow_acquire(iReaderWindow);
3.通过NativeWindow转化为surface
jobject NativeSurfaceManager::Create()
{
jobject local_surface = ANativeWindow_toSurface(_jni,iReaderWindow);
return local_surface;
}
整合到一个方法中: