使用以下非常简单的相机预览活动(来自此处的 google 示例),Nexus 4 相机明显慢于设备的标准相机应用程序:
public class LiveCameraActivity extends Activity implements TextureView.SurfaceTextureListener {
private Camera mCamera;
private TextureView mTextureView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mTextureView = new TextureView(this);
mTextureView.setSurfaceTextureListener(this);
setContentView(mTextureView);
}
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
mCamera = Camera.open();
try {
mCamera.setPreviewTexture(surface);
mCamera.startPreview();
} catch (IOException ioe) {
// Something bad happened
}
}
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
// Ignored, Camera does all the work for us
}
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
mCamera.stopPreview();
mCamera.release();
return true;
}
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
// Invoked every time there's a new Camera preview frame
}
}
我在 Nexus 4 上的应用程序的相机速度一直存在问题,但我在其他设备上没有看到这个问题。我担心这是 Jelly Bean 4.2 的差异,但运行 JB4.2 的 Galaxy Nexus 手机可以正常工作,没有延迟。我意识到这个示例代码使用了 TextureView,但是其他手机在这个示例中没有遇到延迟。
任何帮助将不胜感激。