android 相机手动对焦,Android Camera Api 2手动对焦触摸

Camera API2看起来很奇怪,但是你会发现它很容易.

这个问题的最佳答案是带注释的代码:

private void captureImage() {

try {

//for do this you should have mCameraDevice and mCameraCaptureSession

//get CaptureRequestBuilder.

captureStillBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);

//add target surfaces - for getting image data you should have instance on ImageReader

//with OnImageAvailableListener that will be called when image will be captured

//but for showing on screen you have to use SurfaceView or TextureView

captureStillBuilder.addTarget(mImageReader.getSurface());

//add some details for Request

//in general: you have fields and values for it and you just set what value should be in each field

// auto focus works only when whole control mode in auto

captureStillBuilder.set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_AUTO);

// before capture lock focus

captureStillBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,

CaptureRequest.CONTROL_AF_TRIGGER_START);

// set area for focusing

MeteringRectangle[] focusArea = new MeteringRectangle[1];

focusArea[0] = new MeteringRectangle(/*here set coordinates for focus on */);

captureStillBuilder.set(CaptureRequest.CONTROL_AF_REGIONS, focusArea);

// create callback for this capture

CameraCaptureSession.CaptureCallback callback = new ...

// just run capture to make focused photo

mCameraCaptureSession.capture(captureStillBuilder.build(), callback, null);

} catch (CameraAccessException e) {

e.printStackTrace();

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值