通过imageReader构建Surface

本文介绍了如何在Android中通过ImageReader创建Surface,然后详细阐述了如何读取Surface内容并将其转化为OpenGL可用的texture。首先,从ImageReader获取Window并转化为Surface,接着获取Surface的HWBuffer,利用EGL扩展将其转化为EGLClientBuffer和EGLImage,最后将EGLImage绑定到OpenGL纹理通道。完整代码示例展示了这一过程,为在Unity中显示Android Surface内容提供了可能。
摘要由CSDN通过智能技术生成

1.创建Surface

  1. 通过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;
  }

整合到一个方法中:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值