android camera setfocusareas,Android setFocusArea and Auto Focus

博主在尝试通过代码控制Android相机的焦点区域,但发现相机似乎忽视了预设的焦点区域,即使焦点模式设置为自动并指定了焦点区域,相机依然会自动聚焦到中心或其他区域。问题出现在HTC设备上,初始焦点模式为连续拍照模式,最大焦点区域数为1。调整焦点区域大小和权重未见明显效果。
摘要由CSDN通过智能技术生成

I've been battling with this feature for couple of days now...

It seems, that camera is ignoring(?) focus areas that I've defined. Here is snippets of the code:

Focusing:

protected void focusOnTouch(MotionEvent event) {

if (camera != null) {

Rect rect = calculateFocusArea(event.getX(), event.getY());

Parameters parameters = camera.getParameters();

parameters.setFocusMode(Parameters.FOCUS_MODE_AUTO);

parameters.setFocusAreas(Lists.newArrayList(new Camera.Area(rect, 500)));

camera.setParameters(parameters);

camera.autoFocus(this);

}

}

Focus area calculation:

private Rect calculateFocusArea(float x, float y) {

int left = clamp(Float.valueOf((x / getSurfaceView().getWidth()) * 2000 - 1000).intValue(), focusAreaSize);

int top = clamp(Float.valueOf((y / getSurfaceView().getHeight()) * 2000 - 1000).intValue(), focusAreaSize);

return new Rect(left, top, left + focusAreaSize, top + focusAreaSize);

}

Couple of log events from Camera.AutoFocusCallback#onAutoFocus

Log.d(TAG, String.format("Auto focus success=%s. Focus mode: '%s'. Focused on: %s",

focused,

camera.getParameters().getFocusMode(),

camera.getParameters().getFocusAreas().get(0).rect.toString()));

08-27 11:19:42.240: DEBUG/MyCameraActivity(26268): Auto focus success=true. Focus mode: 'auto'. Focused on: Rect(-109, 643 - -13, 739)

08-27 11:19:55.514: DEBUG/MyCameraActivity(26268): Auto focus success=true. Focus mode: 'auto'. Focused on: Rect(20, 457 - 116, 553)

08-27 11:19:58.037: DEBUG/MyCameraActivity(26268): Auto focus success=true. Focus mode: 'auto'. Focused on: Rect(-159, 536 - -63, 632)

08-27 11:20:00.129: DEBUG/MyCameraActivity(26268): Auto focus success=true. Focus mode: 'auto'. Focused on: Rect(-28, 577 - 68, 673)

Visually it looks like focus succeeds on logged area, but the suddenly it loses focus and focus on center (0, 0), or what takes bigger part of SurfaceView is obtained.

focusAreaSize used in calculation is about 210px (96dp).

Testing on HTC One where Camera.getParameters().getMaxNumFocusAreas() is 1.

Initial focus mode (before first tap) is set to FOCUS_MODE_CONTINUOUS_PICTURE.

Am I doing something wrong here?

Tinkering with Camera.Area rectangle size or weight doesn't show any noticeable effect.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值