最近我正在通过grafika(感谢fadden)学习安卓摄像头和OpenglES.它在大多数设备上都很好,但我遇到了一些设备中的错误,特别是MTK设备(如MT6580,MT8163 ......).
例如,当"CameraCaptureActivity"在MTK中运行时.我收到此错误:
java.lang.NullPointerException:尝试在空对象引用上调用虚方法'void android.hardware.Camera.setPreviewTexture(android.graphics.SurfaceTexture)'
所以我将"handleSetSurfaceTexture"函数更改为:
private void handleSetSurfaceTexture(SurfaceTexture st) {
if(mCamera == null)
{
Log.e(TAG, "mCamera return null");
return;
}
st.setOnFrameAvailableListener(this);
try {
mCamera.setPreviewTexture(st);
} catch (Exception ioe) {
Log.e(TAG, "camera failed handleSetSurfaceTexture");
throw new RuntimeException(ioe);
}
mCamera.startPreview();
}
Run Code Online (Sandbox Code Playgroud)
然后错误更改为:
java.lang.RuntimeException:java.io.IOException:setPreviewTexture在jp.co.cyberagent.android.gpuimage.grafika.CameraCaptureActivity.handleSetSurfaceTexture(CameraCaptureActivity.java:1150)失败
我读了许多其他相机应用程序源代码,我想可能在MTK设备中有Camera和SurfaceRender的同步问题.所以我改变了这样的代码:
private void waitUntilSetup()
{
long l = System.currentTimeMillis();
while ((getMaxTextureSize() == 0) && (System.currentTimeMillis() - l < 3000L))
{
SystemClock.sleep(100L);
}
Log.e(TAG,"getMaxTextureSize() = " + getMaxTextureSize());
}
private int getMaxTextureSize() {
int[] maxTextureSize = new int[1];
GLES20.glGetIntegerv(GL10.GL_MAX_TEXTURE_SIZE, …Run Code Online (Sandbox Code Playgroud)