[英]Android camera preview not working via surfaceTexture
I am trying to draw a camera preview on Android via openGL. 我正在尝试通过openGL在Android上绘制相机预览。 Preview texture is obtain as external EGL image through SurfaceTexture and then I draw it using a fairly simple shader:
预览纹理是通过SurfaceTexture作为外部EGL图像获得的,然后使用相当简单的着色器对其进行绘制:
#extension GL_OES_EGL_image_external : require
precision mediump float;
uniform samplerExternalOES sTexture;
varying vec2 texCoord;
void main() {
gl_FragColor = texture2D(sTexture,texCoord);
}
On nexus 5 it's working for all the preview images up to 1280x960. 在nexus 5上,它适用于所有1280x960以下的预览图像。 However for the biggest 2: 1920x1080 and 1600x1200 the screen is just blank.
但是,对于最大的2:1920x1080和1600x1200,屏幕只是空白。 I set preview size in my camera obtained via camera.getSupportedPreviewSizes , so I am not trying to set anything which is unsupported by the camera.
我在通过camera.getSupportedPreviewSizes获得的相机中设置了预览尺寸,因此我没有尝试设置相机不支持的任何尺寸。
public List<Camera.Size> getSupportedResolutions()
{
List<Camera.Size> previewSizes = mCamera.getParameters().getSupportedPreviewSizes();
List<Camera.Size> pictureSizes = mCamera.getParameters().getSupportedPictureSizes();
pictureSizes.retainAll(previewSizes);
return pictureSizes;
}
private void setResolution(int position)
{
List<Camera.Size> res = getSupportedResolutions();
Camera.Parameters p = mCamera.getParameters();
p.setPictureSize(res.get(position).width, res.get(position).height);
p.setPreviewSize(res.get(position).width, res.get(position).height);
mCamera.setParameters(p);
}
any suggestion what might go be wrong with those resolutions? 任何建议这些决议可能出什么问题? maybe some kind of size limit in opengl?
也许某种OpenGL的大小限制?
I figured the problem. 我发现了问题。 if preview size is larger than the size of my surfaceView I just set improper viewport.
如果预览尺寸大于我的surfaceView的尺寸,我只是设置了不合适的视口。 clamping it by (0, screenW) , (0, screenH) fixes the problem.
通过(0,screenW),(0,screenH)对其进行钳位可以解决此问题。 There is no separate limit for external images, that was fully my fault
外部图像没有单独的限制,这完全是我的错
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.