Android的摄像头 - 设定对焦区域导致运行时异常 [英] Android camera - setting focus area causing runtime exception

查看:997
本文介绍了Android的摄像头 - 设定对焦区域导致运行时异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图开发code的自动对焦相机架中间的大对象。这里是我的code:

I'm trying to develop code that automatically focuses on a large object in the middle of the camera frame. Here's my code:

        Log.i (TAG, "Picking supported size " + selected.width + "x" + selected.height);
        parameters.setPictureSize (selected.width, selected.height);
        try
        {
            parameters.setFocusAreas (Arrays.asList (
                new Camera.Area (
                    new Rect(selected.width/3, selected.height/3, (selected.width*2)/3, (selected.height*2)/3), 
                    1)
                ));
        }
        catch (Exception e)
        {
            Log.w (TAG, "Set focus area failed", e);
        }
        catch (NoClassDefFoundError e)
        {
            Log.w (TAG, "Set focus area failed", e);                
        }
        camera.setParameters (parameters);

在三星Galaxy S2与CM9的结果是:

The results on a Samsung Galaxy S2 with CM9 are:

I/ImageCaptureActivity(28885): Picking supported size 2048x1232
E/ISecCameraHardware(1874): android::status_t android::ISecCameraHardware::checkArea(ssize_t, ssize_t, ssize_t, ssize_t, ssize_t): Camera area right coordinate is invalid 1365
E/ISecCameraHardware(1874): android::status_t android::ISecCameraHardware::setFocusAreas(const android::CameraParameters&): FocusArea parsing failed
W/dalvikvm(28885): threadid=1: thread exiting with uncaught exception (group=0x40a641f8)
E/AndroidRuntime(28885): FATAL EXCEPTION: main
E/AndroidRuntime(28885): java.lang.RuntimeException: setParameters failed
E/AndroidRuntime(28885):    at android.hardware.Camera.native_setParameters(Native Method)
E/AndroidRuntime(28885):    at android.hardware.Camera.setParameters(Camera.java:1423)
E/AndroidRuntime(28885):    at net.meridiandigital.autophoto.ImageCaptureActivity$1.run(ImageCaptureActivity.java:67)

知道为什么这code不工作?右手坐标正在制作(1365)是图像宽度(2048)内的很好,所以为什么系统反对呢?

Any idea why this code isn't working? The right hand coordinate being produced (1365) is well within the image width (2048), so why is the system objecting to it?

推荐答案

从<一个文档href=\"http://developer.android.com/reference/android/hardware/Camera.Parameters.html#getFocusAreas%28%29\">getFocusAreas,双打作为setFocusAreas的文档,

From the documentation of getFocusAreas, which doubles as the documentation for setFocusAreas,

每个重点领域是具有特定重量的矩形。的方向是
  相对于传感器方向,即,传感器所看到的。该
  方向不会受到旋转或镜像
  setDisplayOrientation(INT)。从矩形范围的坐标
  -1000到1000(-1000,-1000)为左上点。 (1000,1000)是右下点

Each focus area is a rectangle with specified weight. The direction is relative to the sensor orientation, that is, what the sensor sees. The direction is not affected by the rotation or mirroring of setDisplayOrientation(int). Coordinates of the rectangle range from -1000 to 1000. (-1000, -1000) is the upper left point. (1000, 1000) is the lower right point

所以,我想说的1365肯定是出界了。

So I'd say the 1365 is definitely out of bounds.

这篇关于Android的摄像头 - 设定对焦区域导致运行时异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆