Reputation: 15199
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);
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)
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?
Upvotes: 2
Views: 2189
Reputation: 17278
From the documentation of getFocusAreas, which doubles as the documentation for setFocusAreas,
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
So I'd say the 1365 is definitely out of bounds.
Upvotes: 9