应用没有正确加载图像???

时间:2012-01-23 03:13:07

标签: android

我加载相机并拍照,然后将拍摄的照片设置为imageview;但是,应用程序始终执行最后拍摄的图像,而不是当前拍摄的图像。

因此,如果我打开应用程序拍照,图像视图就是黑色。关闭应用程序,重新打开并拍摄另一张照片,图像视图现在是第一张拍摄的照片。

???

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        File file = new File(Environment.getExternalStorageDirectory(), "image.jpg");
        System.out.println((Environment.getExternalStorageDirectory() + "/image.jpg"));
        outputFileUri = Uri.fromFile(file);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        startActivityForResult(intent, TAKE_PICTURE);

        setContentView(R.layout.image_process);
         bmp = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory() + "/image.jpg");
        image = (ImageView) findViewById(R.id.imageView1);

            image.setImageBitmap(bmp);

1 个答案:

答案 0 :(得分:1)

由于您使用startActivityForResult开始 Picture Taking 活动,因此您需要将startActivityForResult(..之后的代码移至onActivityResult方法:

/** Called when an activity called by using startActivityForResult finishes. */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
  Log.d(TAG, "Picture taken!");
  setContentView(R.layout.image_process);
  bmp = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory() + "/image.jpg");
  image = (ImageView) findViewById(R.id.imageView1);
  image.setImageBitmap(bmp);
}