我们的应用程序显示了一个摄像头预览,它似乎在所有手机上都能正常工作,除了摩托罗拉 Droid,我们在设置摄像头参数时遇到运行时异常:
java.lang.RuntimeException: setParameters failed
at android.hardware.Camera.native_setParameters(Native Method)
at android.hardware.Camera.setParameters(Camera.java:611)
at com.highwaynorth.andrometer.CameraPreviewSurfaceView.surfaceChanged(CameraPreviewSurfaceView.java:57)
at android.view.SurfaceView.updateWindow(SurfaceView.java:460)
at android.view.SurfaceView.dispatchDraw(SurfaceView.java:287)
at android.view.ViewGroup.drawChild(ViewGroup.java:1525)
这是 surfaceChanged() 的代码,主要取自APIDemos
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
// Now that the size is known, set up the camera parameters and begin
// the preview.
Camera.Parameters parameters = mCamera.getParameters();
parameters.setPreviewSize(w, h);
parameters.setPictureFormat(PixelFormat.JPEG);
parameters.setPreviewFormat(PixelFormat.YCbCr_422_SP);
parameters.setPreviewFrameRate(1);
mCamera.setParameters(parameters);
mCamera.startPreview();
}
有谁知道我们如何设置导致摩托罗拉 Droid 异常的参数有什么问题?