我的onCreate():
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
imageFile = new File(Environment.getExternalStorageDirectory(),
"/image.jpg");
System.out.println(imageFile +" is the path with extentions");
outputFileUri = Uri.fromFile(imageFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, TAKE_PICTURE);
setContentView(R.layout.activity_head_size);
System.out.println("OnCreate");
}
显然,启动相机并等待它完成并返回图像。完成后,应该调用
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}
然而,在我在相机中点击保存后,它会加载onCreate并重新运行相机。然后,如果您重新拍摄图像并点击保存,则会转到活动;但是,不运行onActivityResult?发生了什么事?
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode == 1){
myImage = (ImageView) findViewById(R.id.imageView1);
myBitmap = BitmapFactory.decodeFile( Environment.getExternalStorageDirectory() +
"/image.jpg");
myBitmap = Bitmap.createScaledBitmap(myBitmap, 256, 256, false);
myImage.setImageBitmap(myBitmap);
width = myBitmap.getWidth();
height = myBitmap.getHeight();
orig = new int[width*height];
myBitmap.getPixels(orig, 0, width, 0, 0, width, height);
System.out.println("ready for processing");
}
}
答案 0 :(得分:1)
使用枚举值,而不仅仅是硬编码的int。
if(resultCode == RESULT_OK){
从文档中,RESULT_OK = -1,您正在寻找1.此外,我不知道您在哪里检查requestCode==TAKE_PICTURE
,这也应该是一个预先请求,以确保你正在回应正确的意图。