gpt4 book ai didi

android - 在Android中设置相机对焦区域

转载 作者:IT老高 更新时间:2023-10-28 23:15:23 26 4
gpt4 key购买 nike

根据几个教程和示例,我想出了下一个算法来将相机焦点设置在特定点上,问题是相机完全忽略了该点并执行正常的整体焦点,而不是我指定的矩形区域.我在算法中还缺少什么吗?这已经在几款搭载 Android 4.0 及更高版本的手机上进行了测试,因此这些设备支持焦点区域 API。请注意,我正在编写的应用程序只能在横向模式下运行。

@Override
public boolean onTouchEvent(final MotionEvent event)
{
if (event.getAction() == MotionEvent.ACTION_UP)
{
float x = event.getX();
float y = event.getY();
float touchMajor = event.getTouchMajor();
float touchMinor = event.getTouchMinor();

Rect touchRect = new Rect((int)(x - touchMajor / 2), (int)(y - touchMinor / 2), (int)(x + touchMajor / 2), (int)(y + touchMinor / 2));

this.submitFocusAreaRect(touchRect);
}
}

private void submitFocusAreaRect(final Rect touchRect)
{
Camera.Parameters cameraParameters = camera.getParameters();

if (cameraParameters.getMaxNumFocusAreas() == 0)
{
return;
}

// Convert from View's width and height to +/- 1000

Rect focusArea = new Rect();

focusArea.set(touchRect.left * 2000 / cameraSurfaceView.getWidth() - 1000,
touchRect.top * 2000 / cameraSurfaceView.getHeight() - 1000,
touchRect.right * 2000 / cameraSurfaceView.getWidth() - 1000,
touchRect.bottom * 2000 / cameraSurfaceView.getHeight() - 1000);

// Submit focus area to camera

ArrayList<Camera.Area> focusAreas = new ArrayList<Camera.Area>();
focusAreas.add(new Camera.Area(focusArea, 1000));

cameraParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
cameraParameters.setFocusAreas(focusAreas);
camera.setParameters(cameraParameters);

// Start the autofocus operation

camera.autoFocus(this);
}

最佳答案

在 cameraParameters.setFocusAreas(focusAreas); 之前,你应该添加这个:

cameraParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);

关于android - 在Android中设置相机对焦区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17968132/

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