我们正在为 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);
}