gpt4 book ai didi

Android通过触摸设置手动对焦

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:58:56 25 4
gpt4 key购买 nike

我将通过打开相机来设置我的 Android 应用程序,并通过触摸相机中的点启用手动对焦。相机可以重新聚焦到我指向屏幕的位置。你能告诉我方法或我应该从哪个组件开始修改吗?

下面是我的代码:

public void takePhoto(File photoFile, String workerName, int width, int height, int quality) {
if (getAutoFocusStatus()){
camera.autoFocus(new AutoFocusCallback() {
@Override
public void onAutoFocus(boolean success, Camera camera) {
camera.takePicture(shutterCallback, rawCallback, jpegCallback);
}
});
}else{
camera.takePicture(shutterCallback, rawCallback, jpegCallback);
}

this.photoFile = photoFile;
this.workerName = workerName;
this.imageOutputWidth = width;
this.imageOutputHeight = height;
}

public void takePhoto(File photoFile, int width, int height, int quality) {
takePhoto(photoFile, null, width, height, quality);
}

最佳答案

虽然这个答案没有展示如何聚焦在一个单一的区域,但它绝对有助于展示如何准确地聚焦相机。

这是我所做的。这适用于我的设备(HTC 的 Droid DNA),内置在 Android Studio 中

OnSurfaceChanged()OnSurfaceCreated() 中,我有以下代码:(mCamera 是我的私有(private) Camera 对象)

        mCamera.stopPreview();
Camera.Parameters p = mCamera.getParameters();
p.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);

mCamera.setParameters(p);
mCamera.setPreviewDisplay(surfaceHolder);
mCamera.startPreview();
mCamera.autoFocus(null);

在构造函数中,你必须放置

        setFocusable(true);
setFocusableInTouchMode(true);

这将允许您接收焦点事件。至于捕捉他们……

 public boolean onTouchEvent(MotionEvent event){
if(event.getAction() == MotionEvent.ACTION_DOWN){
Log.d("down", "focusing now");

mCamera.autoFocus(null);
}

return true;
}

关于Android通过触摸设置手动对焦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12851154/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com