我正在尝试开发自动聚焦在相机框架中间的大对象的代码。这是我的代码:
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的结果是:
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)
知道为什么这段代码不起作用?产生的右手坐标(1365)完全在图像宽度(2048)内,那么为什么系统会反对呢?
答案 0 :(得分:9)
来自getFocusAreas的文档,该文档兼作setFocusAreas的文档,
每个焦点区域都是指定重量的矩形。方向是 相对于传感器方向,即传感器看到的内容。该 方向不受旋转或镜像的影响 setDisplayOrientation(INT)。矩形的坐标范围从 -1000到1000.( - 1000,-1000)是左上角的点。 (1000,1000)是右下角
所以我说1365肯定是出界的。