3

我想使用 Android 相机一次拍摄多张图像。当用户单击AlertDialog. 但我想在不按任何按钮的情况下捕捉图像。我需要自动捕捉四张图像。

captureButton.setOnClickListener( new OnClickListener() {
        public void onClick(View v) {
mCamera.takePicture(shutterCallback, null, mPicture);
            new Handler().postDelayed(new Runnable() {
                public void run() {

                    if(count==4 || count > 4) //static variable count = 0
                        {

                        showAlertMSGOnUIThread("Warning","You have taken 4 photos");

                       }

                    else if(count<4)
                    {

                        final AlertDialog.Builder builder1 = new AlertDialog.Builder(ScanBill.this);


                        final TextView msg = new TextView(ScanBill.this);
                        final TextView title = new TextView(ScanBill.this);
                        title.setText("Warning");
                        title.setPadding(0, 10, 0, 10);
                        title.setTextSize(20);
                        title.setGravity(Gravity.CENTER);
                        title.setTextColor(Color.WHITE);
                        title.setBackgroundColor(Color.parseColor("#FF0D4C6A"));
                        msg.setText("Picture taken successfully would you like to Retake?");
                        msg.setPadding(0, 10, 0, 10);
                        msg.setGravity(Gravity.CENTER);
                        msg.setTextSize(18);
                        // msg.setBackgroundColor(Color.parseColor("#FF0D4C6A"));
                        Utilities.writeIntoLog("UI Init successfull");

                        AlertDialog.Builder builder = new AlertDialog.Builder(
                                ScanBill.this);
                        builder.setCustomTitle(title);
                        builder.setView(msg).setPositiveButton("YES",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog,
                                            int id) {
                                        dialog.dismiss();

                                        onCreate(null);

                                    }
                                });


                        builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface dialog,
                                    int id) {

                                dialog.dismiss();
                            }
                        });
                        AlertDialog alert = builder.create();
                        alert.setCanceledOnTouchOutside(false);
                        alert.show();
                        Utilities.writeIntoLog("Alert Display Successfull");



                    }


                }
            }, 1000); 



        }
    });

这是我的PictureCallback实现:

PictureCallback mPicture = new PictureCallback() {

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

        //File pictureFile = getOutputMediaFile();
        //if (pictureFile == null){
            //return;
        //}
        System.out.println("PictureCallback() method is called");
        FileOutputStream outStream = null;
        try {
            String file_path = Environment
            .getExternalStorageDirectory()
            + "/ScanBills/"+customerName;
            // write to local sandbox file system
            //                  outStream = CameraDemo.this.openFileOutput(String.format("%d.jpg", System.currentTimeMillis()), 0); 
            // Or write to sdcard
            File dir = new File(file_path);
            if (!dir.exists())
                dir.mkdirs();

            File file = new File(dir, "Bill_ "+count+".JPEG");
            outStream = new FileOutputStream(file); 
            outStream.write(data);
            outStream.close();
            count=count+1;
            System.out.println("Picture count :"+count);

        } catch (FileNotFoundException e) {

        } catch (IOException e) {

        }

    }

};

按下拍摄按钮后,我想拍摄 4 张照片(图像),没有任何警报消息或对话框。这可能吗?提前致谢。

4

1 回答 1

0

在您的按钮单击事件中尝试以下类似的操作..

new Thread(new Runnable() {

            @Override
            public void run() {
                while(count < 4) {
                    FileNm = "Image" + count + ".jpg";
                       mCamera.takePicture(null, mPictureCallback, mPictureCallback);
                       count++;
                   try {
                    Thread.sleep(3000);
                } catch (InterruptedException exception) {
                    exception.printStackTrace();
                }
            }
        }
}).start();
于 2013-10-15T11:05:52.587 回答