在 monkey test 测试中出现了一例 RuntimeException ,即 setParameters failed.
LOG显示为:
09-01 18:47:17.348 15656 15675 E AndroidRuntime: FATAL EXCEPTION: Camera Handler Thread
09-01 18:47:17.348 15656 15675 E AndroidRuntime: Process: com.android.camera, PID: 15656
09-01 18:47:17.348 15656 15675 E AndroidRuntime: java.lang.RuntimeException: setParameters failed
09-01 18:47:17.348 15656 15675 E AndroidRuntime: at android.hardware.Camera.native_setParameters(Native Method)
09-01 18:47:17.348 15656 15675 E AndroidRuntime: at android.hardware.Camera.setParameters(Camera.java:1760)
09-01 18:47:17.348 15656 15675 E AndroidRuntime: at com.android.camera.CameraManager$CameraHandler.handleMessage(CameraManager.java:260)
09-01 18:47:17.348 15656 15675 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
09-01 18:47:17.348 15656 15675 E AndroidRuntime: at android.os.Looper.loop(Looper.java:136)
09-01 18:47:17.348 15656 15675 E AndroidRuntime: at android.os.HandlerThread.run(HandlerThread.java:61)
最终查到:
09-01 18:47:17.338 235 4175 E QCameraParameters: int32_t qcamera::QCameraParameters::setZoom(const qcamera::QCameraParameters&): invalid value -1 out of (0, 60)
setZoom 的值存在异常。
解决方案就是在 setZoom 的时候,先检查 mZoomValue 是否合法,如果不合法,则 return 掉。
1 try { 2 int PreviewWidth = 0; 3 int PreviewHeight = 0; 4 WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);//获取窗口的管理器 5 Display display = wm.getDefaultDisplay();//获得窗口里面的屏幕 6 Camera.Parameters parameters = mCamera.getParameters(); 7 // 选择合适的预览尺寸 8 List<Camera.Size> sizeList = parameters.getSupportedPreviewSizes(); 9 10 // 如果sizeList只有一个我们也没有必要做什么了,因为就他一个别无选择 11 if (sizeList.size() > 1) { 12 Iterator<Camera.Size> itor = sizeList.iterator(); 13 while (itor.hasNext()) { 14 Camera.Size cur = itor.next(); 15 if (cur.width >= PreviewWidth 16 && cur.height >= PreviewHeight) { 17 PreviewWidth = cur.width; 18 PreviewHeight = cur.height; 19 break; 20 } 21 } 22 } 23 parameters.setPreviewSize(PreviewWidth, PreviewHeight); //获得摄像区域的大小 24 parameters.setPreviewFrameRate(3);//每秒3帧 每秒从摄像头里面获得3个画面 25 parameters.setPictureFormat(PixelFormat.JPEG);//设置照片输出的格式 26 parameters.set("jpeg-quality", 85);//设置照片质量 27 parameters.setPictureSize(PreviewWidth, PreviewHeight);//设置拍出来的屏幕大小 28 // 29 mCamera.setParameters(parameters);//把上面的设置 赋给摄像头 30 mCamera.setPreviewDisplay(mySurfaceView.getHolder());//把摄像头获得画面显示在SurfaceView控件里面 31 mCamera.startPreview();//开始预览 32 mPreviewRunning = true; 33 } catch (IOException e) { 34 Log.e(TAG, e.toString()); 35 }
1 //List<Size> pictureSizes = mCameraDevice.getCamera().getParameters().getSupportedPictureSizes(); 2 List<Size> pictureSizes = mParameters.getSupportedPictureSizes(); 3 int length = pictureSizes.size(); 4 for (int i = 0; i < length; i++) { 5 LOGD("SupportedPictureSizes : " + pictureSizes.get(i).width + "x" + pictureSizes.get(i).height); 6 } 7 8 //List<Size> previewSizes = mCameraDevice.getCamera().getParameters().getSupportedPreviewSizes(); 9 List<Size> previewSizes = mParameters.getSupportedPreviewSizes(); 10 length = previewSizes.size(); 11 for (int i = 0; i < length; i++) { 12 LOGD("SupportedPreviewSizes : " + previewSizes.get(i).width + "x" + previewSizes.get(i).height); 13 }
http://www.eoeandroid.com/thread-28137-2-1.html
http://bbs.csdn.net/topics/370195903?page=1#post-396249333