0

I need to captured an image and display it in Image View

This is what i do;

btnLaunchCamera.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        activeTakePhoto();
    }
});


private void activeTakePhoto() {
    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    File photo = new File(Environment.getExternalStorageDirectory(), FILE_NAME);
    intent.putExtra(MediaStore.EXTRA_OUTPUT,
            Uri.fromFile(photo));
    imageUri = Uri.fromFile(photo);
    startActivityForResult(intent, 119);
}

enter image description here

When i press OK, it takes me the image view, This is what i do to display picture in image view.

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        selectedImage = imageUri;
        Intent intent= new Intent(CameraLauncherActivity.this, MainActivity.class);
        intent.putExtra("imageBitmap", selectedImage);
        startActivity(intent);
}

MainActivity

imageUri=  (Uri) intentData.getExtras().get("imageBitmap");
mImageView.setImageURI(imageUri);

enter image description here

dev90
  • 7,187
  • 15
  • 80
  • 153
  • This is quite old and big issue on android. Id depends on device/camera manufacturer and eventually you need to rotate your image. See here: https://stackoverflow.com/questions/14066038/why-does-an-image-captured-using-camera-intent-gets-rotated-on-some-devices-on-a and here https://stackoverflow.com/questions/21085105/get-orientation-of-image-from-mediastore-images-media-data/30572852#30572852 – eleven Feb 05 '18 at 16:13
  • Thanks @eleven ! – dev90 Feb 05 '18 at 17:41

0 Answers0