最近3年我一直在使用Camera API 2,一切正常,但是最近10天无法使用。当前未调用 TextureView.SurfaceTextureListener ,因此无法打开相机预览,打开的是黑屏。有什么问题或相关相机API2中的任何更新。请在下面找到代码...
textureView = (TextureView) findViewById(R.id.texture);
assert textureView != null;
textureView.setSurfaceTextureListener(textureListener);
TextureView.SurfaceTextureListener textureListener = new TextureView.SurfaceTextureListener() {
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { //open your camera here
openCamera();
}
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { // Transform you image captured size according to the surface width and height
Log.e("onSurfaceTexture","onSurfaceTextureSizeChanged");
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
Log.e("onSurfaceTexture","onSurfaceTextureDestroyed");
return false;
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
Log.e("onSurfaceTextureUpdated","onSurfaceTextureUpdated");
}
};
在上述代码中,可以在最近3年内正常运行,但在过去10天中 TextureView.SurfaceTextureListener 无效,因此 openCamera < / strong>方法未调用,因此显示黑屏。请提出任何解决此问题的想法。
答案 0 :(得分:0)
我也遇到了同样的问题,但是我的问题通过在清单文件中添加一行来解决,即android:hardwareAccelerated =“ true”。