Hi All,
As I finally succeeded to get "setfocusareas" work with the help of Agraham's code and many other answers (see post-
251700), I upload here an updated version of CameraEX class including:
- GetMaxNumFocusAreas
- GetFocusAreas
- SetFocusArea(area As Rect, weight As Int )
Here are some explanations found on Android pages
'Before using this API or setFocusAreas(List), apps should call getMaxNumFocusAreas() to know the maximum number of focus areas first.
'If the value is 0, focus area is not supported.
'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.
'The width and height of focus areas cannot be 0 or negative.
'The weight must range from 1 to 1000. The weight should be interpreted as a per-pixel weight - all pixels in the area have the specified weight.
'This means a small area with the same weight as a larger area will have less influence on the focusing than the larger area.
'Focus areas can partially overlap and the driver will add the weights in the overlap region.
'A special case of a null focus area list means the driver is free to select focus targets as it wants.
'For example, the driver may use more signals to select focus areas and change them dynamically.
'Apps can set the focus area list to null if they want the driver to completely control focusing.
'Focus areas are relative to the current field of view (getZoom()).
'No matter what the zoom level is, (-1000,-1000) represents the top of the currently visible camera frame.
'The focus area cannot be set to be outside the current field of view, even when using zoom.
'Focus area only has effect if the current focus mode is FOCUS_MODE_AUTO, FOCUS_MODE_MACRO, FOCUS_MODE_CONTINUOUS_VIDEO, or FOCUS_MODE_CONTINUOUS_PICTURE.
The main in the ZIP includes an example of what can be done with this:
- launch the camera
- press on the screen and a rectangle should appear to indicate where the focus will be done
- if successfull it becomes green, else it turns to red
warning:
As the 3 new routines are supported only on API = 14 and more, I've limited the usage to "new" devices with a test of the API version so that the class remains compatible with 2.3+ devices...
Code:
'check api level and focus supported
FocusSupported = False
Dim r As Reflector
api = r.GetStaticField("android.os.Build$VERSION", "SDK_INT")
If api >= 14 Then
If camEx.GetMaxNumFocusAreas <> 0 Then FocusSupported = True
End If
Log("focus supported : " & FocusSupported)
I would appreciate if somebody who owns a device < API 14 could try the code to check if everything works well with this "is focus supported" test ...
==> the rectangle on the screen should not be displayed
Please note that the code only supports one focusarea. My S3 does not support more !
Have fun
ALain