用这个帮助mi,我做了一个使用相机并闪存qr代码的应用程序,但相机不响应我有这个代码我试图先看到相机的东西,我将与QR的识别工作代码任何帮助都会很好
public class activity_flashqr_normalscreensize extends Activity implements
SurfaceHolder.Callback {
private Button boton;
private SurfaceView VisorQR;
SurfaceHolder surfaceHolder;
android.hardware.Camera theCamera;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.flashqr_normalscreensize_esp);
boton = (Button)findViewById(R.id.btnfoto);
VisorQR = (SurfaceView)findViewById(R.id.visorqr);
surfaceHolder = VisorQR.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS)
}
public void refreshCamera() {
if (surfaceHolder.getSurface() == null) {
return;
}
try {
theCamera.stopPreview();
}
catch (Exception e) {
}
try {
theCamera.setPreviewDisplay(surfaceHolder);
theCamera.startPreview();
}
catch (Exception e) {
}
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
try {
theCamera.lock();
theCamera = android.hardware.Camera.open();
}
catch (RuntimeException e) {
System.err.println(e);
return;
}
android.hardware.Camera.Parameters param;
param = theCamera.getParameters();
param.setPreviewSize(350, 250);
theCamera.setParameters(param);
try {
theCamera.setPreviewDisplay(surfaceHolder);
theCamera.startPreview();
}
catch (Exception e) {
System.err.println(e);
return;
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
refreshCamera();
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
theCamera.stopPreview();
theCamera.release();
theCamera = null;
}
}
答案 0 :(得分:0)
我找到了一个很好的教程来实现我想要的东西
http://www.codepool.biz/how-to-implement-a-simple-barcode-scan-application-on-android.html
也要使用zxing库你需要将它添加到build.gradle.app中 依赖于android studio
compile 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
compile 'com.google.zxing:core:3.2.1'