从相机自动捕捉图像?

时间:2017-02-02 06:49:17

标签: android camera

我有qrReader应用程序所以在ActivityResult中我写入意图进入相机如果我有回应我想要的是可以在意图进入相机后自动拍照并自动对焦后吗?(我该怎么办?添加自动捕获)

        button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            IntentIntegrator intentIntegrator = new IntentIntegrator(activity);
            intentIntegrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
            intentIntegrator.setPrompt("Scan");
            intentIntegrator.setCameraId(0);
            intentIntegrator.setBeepEnabled(false);
            intentIntegrator.setBarcodeImageEnabled(false);
            intentIntegrator.initiateScan();

        }
    });
}

@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    final IntentResult result = IntentIntegrator.parseActivityResult(requestCode,resultCode,data);
    if(result!= null){
                if(result.getContents()==null){
                    Toast.makeText(getApplicationContext(),"you canceled the scanning",Toast.LENGTH_LONG).show();
                }
                else {
                    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    textView.setText(result.getContents());
                    startActivityForResult(intent, TAKE_PICTURE);



                }



    }

    super.onActivityResult(requestCode, resultCode, data);
}

1 个答案:

答案 0 :(得分:0)

添加以下代码:

写一个方法

ShutterCallback shutterCallback = new ShutterCallback() {
        public void onShutter() {
            //           Log.d(TAG, "onShutter'd");
        }
    };

    PictureCallback rawCallback = new PictureCallback() {
        public void onPictureTaken(byte[] data, Camera camera) {
            //           Log.d(TAG, "onPictureTaken - raw");
        }
    };

    PictureCallback jpegCallback = new PictureCallback() {
        public void onPictureTaken(byte[] data, Camera camera) {
            new SaveImageTask().execute(data);
            resetCam();
            Log.d(TAG, "onPictureTaken - jpeg");
        }
};

并在你的onResult中将其称为

public show(): void {
    this.visible = true;
    this.visibleAnimate = true;
    console.log(this.src)
    this.DocURL = this.sanitizer.bypassSecurityTrustResourceUrl(this.src);
    console.log(this.DocURL);
}


constructor(private sanitizer: DomSanitizer) {
    this.visible = false;
    this.visibleAnimate = false;

    this.DocURL = this.sanitizer.bypassSecurityTrustResourceUrl(window.location.host + "/pdf.pdf");
}

要在相机预览类中回答您的问题,请添加:

<div style=" height:650;width:870">
    <object width="870" height="650" type="application/pdf" [data]="DocURL" id="doc" #doc>
        <p>Not able to display the document</p>
    </object>
    <div style="display:none">
        <iframe id="fred" #fred style="border:1px solid #666CCC" title="PDF in an i-Frame" [src]="DocURL" frameborder="1" scrolling="auto" height="1100" width="850" ></iframe>
    </div>
</div>