我想自动对焦矿石有更好的质量凸轮可以有人帮助我吗?我希望我的qr扫描仪能够自动对焦,我想将凸轮切换到前后。 这是我的代码......
public class MainActivity extends AppCompatActivity {
SurfaceView cameraPreview;
TextView txtResult;
BarcodeDetector barcodeDetector;
CameraSource cameraSource;
ImageButton cameraSwitch;
final int RequestCameraPermissionID = 1001;
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode) {
case RequestCameraPermissionID: {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
return;
}
try
{
cameraSource.start(cameraPreview.getHolder());
cameraPreview.findFocus();
} catch (IOException e) {
e.printStackTrace();
}
}
}
break;
}
}
//QR-code scanner
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cameraPreview = (SurfaceView) findViewById(R.id.cameraPreview);
cameraSwitch = (ImageButton) findViewById(R.id.cameraSwitch);
txtResult = (TextView) findViewById(R.id.txtResult);
barcodeDetector = new BarcodeDetector.Builder(this)
.setBarcodeFormats(Barcode.QR_CODE)
.build();
cameraSource = new CameraSource
.Builder(this, barcodeDetector)
.setRequestedPreviewSize(500, 500)
.build();
cameraSwitch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
}
});
任何帮助都会很好。
答案 0 :(得分:0)
QrCodeReaderView
库将帮助您做到这一点。该库使用 ZXING Library
您可以在此处获取图书馆:https://github.com/dlazaro66/QRCodeReaderView
您可以设置自动对焦,也可以更换相机。
qrCodeReaderView = (QRCodeReaderView) findViewById(R.id.qrdecoderview);
qrCodeReaderView.setOnQRCodeReadListener(this);
// Use this function to enable/disable decoding
qrCodeReaderView.setQRDecodingEnabled(true);
// Use this function to change the autofocus interval (default is 5 secs)
qrCodeReaderView.setAutofocusInterval(2000L);
// Use this function to enable/disable Torch
qrCodeReaderView.setTorchEnabled(true);
// Use this function to set front camera preview
qrCodeReaderView.setFrontCamera();
// Use this function to set back camera preview
qrCodeReaderView.setBackCamera();
希望有所帮助:)