Aaron Decker
Aaron Decker

Reputation: 558

App not loading images right???

I load the camera and take a picture, then set the picture taken into an imageview; however, the app always does the last image taken, not the current one.

So, if I open the app and take a picture, the image view is black. Close app, reopen and take another picture, the image view is now the first picture taken.

???

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);

Upvotes: 0

Views: 77

Answers (1)

Marvin Pinto
Marvin Pinto

Reputation: 30990

Since you're starting your Picture Taking activity with startActivityForResult, you need to move the code following startActivityForResult(.. to the onActivityResult method:

/** 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);
}

Upvotes: 1

Related Questions