Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camera setFocusAreas() not working Android 4.0

I'm creating a camera app that will use a tap to focus function, much like many of the standard camera apps come with. I first get the (x,y) coordinate of a touch event, then deliver this value to the UI. Then, I try to set the focus area, like this:

Rect newRect = new Rect(left,top,right, bottom);
Camera.Parameters params = mCamera.mCameraInstance.getParameters();
Camera.Area focusArea = new Camera.Area(newRect, 1000);
List<Camera.Area> focusAreas = new ArrayList<Camera.Area>();
focusAreas.add(focusArea);
params.setFocusAreas(focusAreas);

However, it appears to have no effect. So, I hardcoded some values into the rectangle (this way, I can rule out bad coordinates from the touch event). According to the docs, it is looking for a coordinate in the space (-1000, -1000)(upper left) to (1000, 1000)(bottom right).

So I replaced my rectangle above with this one:

//should target a 100x100 square in the center of the screen
Rect newRect = new Rect(-50,-50,50, 50);

And still, seems to have no effect. I know my camera supports setting focus areas, because first of all, the camera app uses it successfully, and also params.getMaxNumFocusAreas() returns 1.

If anyone has used this with success in the past, please let me know!!

Edit:

I found this similar question that seems to also indicate that this API simply doesn't work on Android 4.0 devices and up (im testing on 4.1.1, Galaxy S3). And yet, the camera apps on these devices still definitely has tap-to-focus functionality. What am I missing???

like image 897
Jameo Avatar asked Mar 22 '13 19:03

Jameo


1 Answers

I had this problem today :/

And after hours of struggling, I found the solution!

It's strange, but it appears that setting focus-mode to "macro" right before setting focus-areas solved the problem ;)

params.setFocusMode(Camera.Parameters.FOCUS_MODE_MACRO);
params.setFocusAreas(focusAreas);
mCamera.setParameters(params);

I have Galaxy S3 with Android 4.1.2

I hope this will work for you either :)

like image 112
Grzegorz D. Avatar answered Oct 12 '22 13:10

Grzegorz D.