我想使用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张照片(图像),没有任何警告信息或对话框。这可能吗? 提前谢谢。
答案 0 :(得分: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();