Camera.setParameters和setFocusAreas的RuntimeException

时间:2014-12-30 11:47:20

标签: java android android-camera

我想使用此代码实现触摸焦点

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
                @Override
                public void touchFocus(Rect tfocusRect) {
                    if (_.mCamera == null) return;


//                   camera.stopFaceDetection();

                     //Convert from View's width and height to +/- 1000
                  final Rect targetFocusRect = new Rect(
                    tfocusRect.left * 2000/sfv.getWidth() - 1000,
                    tfocusRect.top * 2000/sfv.getHeight() - 1000,
                    tfocusRect.right * 2000/sfv.getWidth() - 1000,
                    tfocusRect.bottom * 2000/sfv.getHeight() - 1000);

                  final List<Camera.Area> focusList = new ArrayList<Camera.Area>();
                  Camera.Area focusArea = new Camera.Area(targetFocusRect, 1000);
                  focusList.add(focusArea);
                  Parameters para = _.mCamera.getParameters();
                  Log.d(TAG,para.getMaxNumFocusAreas() + " >> " + tfocusRect.toString());


                  para.setFocusAreas(focusList);
                  para.setMeteringAreas(focusList);
                  _.mCamera.setParameters(para);//HERE THE ERROR

                 _.mCamera.autoFocus(myAutoFocusCallback);

                }

在第_.mCamera.setParameters(para);//HERE THE ERROR行,有一个调用堆栈:

12-30 14:27:31.295: D/AndroidRuntime(853): Shutting down VM
12-30 14:27:31.295: W/dalvikvm(853): threadid=1: thread exiting with uncaught exception (group=0x4164ad58)
12-30 14:27:31.345: E/AndroidRuntime(853): FATAL EXCEPTION: main
12-30 14:27:31.345: E/AndroidRuntime(853): Process: my.app.camera, PID: 853
12-30 14:27:31.345: E/AndroidRuntime(853): java.lang.RuntimeException: setParameters failed
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.hardware.Camera.native_setParameters(Native Method)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.hardware.Camera.setParameters(Camera.java:1775)
12-30 14:27:31.345: E/AndroidRuntime(853):  at my.app.camera.AAP$1.touchFocus(AAP.java:128)
12-30 14:27:31.345: E/AndroidRuntime(853):  at my.app.camera.CameraSurfaceView.onTouchEvent(CameraSurfaceView.java:50)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.View.dispatchTouchEvent(View.java:7764)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2245)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1946)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2245)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1946)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2245)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1946)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2245)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1946)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2245)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1946)
12-30 14:27:31.345: E/AndroidRuntime(853):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2151)
12-30 14:27:31.345: E/AndroidRuntime(853):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1532)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.app.Activity.dispatchTouchEvent(Activity.java:2458)
12-30 14:27:31.345: E/AndroidRuntime(853):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2099)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.View.dispatchPointerEvent(View.java:7944)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3953)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3832)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3518)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3575)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5538)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5518)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5489)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5618)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.os.MessageQueue.nativePollOnce(Native Method)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.os.MessageQueue.next(MessageQueue.java:138)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.os.Looper.loop(Looper.java:123)
12-30 14:27:31.345: E/AndroidRuntime(853):  at android.app.ActivityThread.main(ActivityThread.java:5095)
12-30 14:27:31.345: E/AndroidRuntime(853):  at java.lang.reflect.Method.invokeNative(Native Method)
12-30 14:27:31.345: E/AndroidRuntime(853):  at java.lang.reflect.Method.invoke(Method.java:515)
12-30 14:27:31.345: E/AndroidRuntime(853):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-30 14:27:31.345: E/AndroidRuntime(853):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
12-30 14:27:31.345: E/AndroidRuntime(853):  at dalvik.system.NativeStart.main(Native Method)

为什么呢?坐标是正确的。结果rect的值介于[-1000,1000]之间。

Android 4.4.4

没有

          para.setFocusAreas(focusList);
          para.setMeteringAreas(focusList);

一切正常。 _.mCamera的另一个设置也可以。

0 个答案:

没有答案