gpt4 book ai didi

Android 相机只对焦一次

转载 作者:行者123 更新时间:2023-12-04 23:43:11 25 4
gpt4 key购买 nike

我们正在为 Vuzix M100 开发一个应用程序,它应该连续读取条形码并在 textView 中显示结果。因此,相机每 5 秒拍摄一张照片,并将位图发送给 zxing 条码扫描器。我们几乎完成了,但相机只聚焦在第一张照片上。有什么建议么?
这是我们代码的重要部分:

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

tv = (TextView) findViewById(R.id.textView1);

mPreview = (SurfaceView) findViewById(R.id.sv1);
mPreview.getHolder().addCallback(this);

mCamera = Camera.open();
final Parameters param = mCamera.getParameters();

param.setJpegQuality(100);
param.setPictureSize(1600, 1200);
param.setFocusMode(param.FOCUS_MODE_CONTINUOUS_PICTURE);
param.setSceneMode(Parameters.SCENE_MODE_BARCODE);

mCamera.setParameters(param);

final Handler h = new Handler();
final int delay = 5000;

h.postDelayed(new Runnable(){
int count = 1;
public void run(){
tryAutoFocus();
param.setFocusMode(param.FOCUS_MODE_FIXED);
param.setFocusMode(param.FOCUS_MODE_AUTO);

h.postDelayed(this, delay);
}
}, delay);

}

.
private void tryAutoFocus() {

final PictureCallback myPictureCallback = new PictureCallback() {

@Override
public void onPictureTaken(byte[] data, Camera camera) {

try {
Options options = new BitmapFactory.Options();
options.inScaled = false;
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length, options);
createExternalStoragePublicPicture(bmp);

} catch (Exception e) {
e.printStackTrace();
}

}
};

AutoFocusCallback myAutoFocusCallback = new AutoFocusCallback() {

@Override
public void onAutoFocus(boolean success, Camera arg1) {
// TODO: Problem: Fokussiert nur beim ersten Foto

mCamera.takePicture(null, null, null, myPictureCallback);

mCamera.cancelAutoFocus();
mCamera.startPreview();
}
};

mCamera.autoFocus(myAutoFocusCallback);

}

最佳答案

这是一个老问题,但仍然:
请注意,通过 Camera.Parameters.setSceneMode() 设置场景实际上可能会覆盖任何先前的设置。引用 API documentation :

Changing scene mode may override other parameters (such as flash mode, focus mode, white balance). For example, suppose originally flash mode is on and supported flash modes are on/off. In night scene mode, both flash mode and supported flash mode may be changed to off. After setting scene mode, applications should call getParameters to know if some parameters are changed.


此外,文档暗示不仅可以覆盖当前设置,还可以覆盖支持的参数值。
所以我建议:
  • 设置对焦模式前先设置场景模式
  • 设置场景模式后,使用 getSupportedFocusModes() 检查是否仍支持所需的对焦模式
  • 关于Android 相机只对焦一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38500242/

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