用户可以使用以下方法用相机拍照:
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
startActivityForResult(takePictureIntent, Constants.REQUEST_IMAGE_CAPTURE);
}
}
在OnActivityResult中,我想呈现使用JNI编辑的2个不同版本的拍摄图像。所以我试图展示一个AlertDialog:
AlertDialog.Builder alertadd = new AlertDialog.Builder(this);
LayoutInflater factory = LayoutInflater.from(this);
final View view = factory.inflate(R.layout.dialog_segmen, null);
ImageView iv1 = (ImageView) view.findViewById(R.id.imageView1);
ImageView iv2 = (ImageView) view.findViewById(R.id.imageView2);
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.displayImage("file:///" + outputWahetFile, iv1);
imageLoader.displayImage("file:///" + outputCahtFile, iv2);
alertadd.setView(view);
alertadd.setNeutralButton("Here!", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
}
});
alertadd.create().show();
但根本没有任何事情发生。没有错误,没有对话,没有。这也适用于非自定义对话框,如下所示:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("message")
.setTitle("title");
AlertDialog dialog = builder.create();
dialog.show();
整个onActivityResult()
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == Constants.REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
String id = "" + System.currentTimeMillis();
File inputDir = new File(getFilesDir() + File.separator + mUserMail + Constants.DIR_INPUT);
inputDir.mkdirs();
File inputFile = new File(inputDir + File.separator + id + Constants.END_JPG);
File textureDir = new File(getFilesDir() + File.separator + mUserMail + Constants.DIR_TEXTURE + File.separator + id);
textureDir.mkdirs();
File textureWahetFile = new File(textureDir + File.separator + USITHelper.ALGO_SEG_WAHET_SHORT + Constants.END_PNG);
File textureCahtFile = new File(textureDir + File.separator + USITHelper.ALGO_SEG_CAHT_SHORT + Constants.END_PNG);
File output = new File(getFilesDir() + File.separator + mUserMail + Constants.DIR_SEGMENTS + File.separator + id);
output.mkdirs();
File outputWahetFile = new File(output + File.separator + USITHelper.ALGO_SEG_WAHET_SHORT + Constants.END_JPG);
File outputCahtFile = new File(output + File.separator + USITHelper.ALGO_SEG_CAHT_SHORT + Constants.END_JPG);
try {
FileOutputStream fos = new FileOutputStream(inputFile);
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 99, fos);
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
IrisEntry e = new IrisEntry();
e.setId(id);
e.setUserId(mUserMail);
mUSITHelper.segmentPicture(inputFile, textureWahetFile, outputWahetFile, USITHelper.ALGO_SEG_WAHET_SHORT);
mUSITHelper.segmentPicture(inputFile, textureCahtFile, outputCahtFile, USITHelper.ALGO_SEG_CAHT_SHORT);
/////// APPROACH ONE - standard dialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("message")
.setTitle("title");
AlertDialog dialog = builder.create();
dialog.show();
/////// APPROACH TWO - custom dialog
AlertDialog.Builder alertadd = new AlertDialog.Builder(this);
LayoutInflater factory = LayoutInflater.from(this);
final View view = factory.inflate(R.layout.dialog_segmen, null);
ImageView iv1 = (ImageView) view.findViewById(R.id.imageView1);
ImageView iv2 = (ImageView) view.findViewById(R.id.imageView2);
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.displayImage("file:///" + outputWahetFile, iv1);
imageLoader.displayImage("file:///" + outputCahtFile, iv2);
alertadd.setView(view);
alertadd.setNeutralButton("Here!", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
}
});
alertadd.create().show();
/////// APPROACH THREE- dialog activity
Intent i = new Intent(this, SegmentationDialog.class);
i.putExtra(Constants.EXTRA_CAHT_PATH, outputCahtFile.getPath());
i.putExtra(Constants.EXTRA_WAHET_PATH, outputWahetFile.getPath());
startActivityForResult(i, Constants.REQUEST_SEGEMNTATION_CHOOSE);
addItem(e);
}
if (requestCode == Constants.REQUEST_SEGEMNTATION_CHOOSE && resultCode == RESULT_OK) {
}
if (requestCode == Constants.REQUEST_SEGEMNTATION_CHOOSE && resultCode == RESULT_CANCELED) {
dispatchTakePictureIntent();
}
}
我厌倦了三种不同方法中的每一种(不合并)。目前唯一可行的方法是自定义对话框Activity,但我想继续使用已有的IrisEntry对象