I am building an application that uses camera to take pictures. Here is my source code to do this:
File file = new File(Environment.getExternalStorageDirectory(),
imageFileName);
imageFilePath = file.getPath();
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
//Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
startActivityForResult(intent, ACTIVITY_NATIVE_CAMERA_AQUIRE);
On onActivityResult()
method, I use BitmapFactory.decodeStream()
to pickup the image.
When I run my application on Nexus one, it runs well. But when I run on Samsung Galaxy S or HTC Inspire 4G, the image's direction is not correct.
- Capture with portrait mode, the real image (save on SD card) always rotates 90 degree.
Image preview after shot --------- Real image on SD card
- Capture with landscape mode, all things are good.
Image preview after shot --------- Real image on SD card
Just encounter the same issue here, the code snippet below works for me:
hope this does help :)
two One line solutions using Picasso and glide library
After spending a lot of time with a lot of solutions for image rotation problem I finally found two simple solutions. We don't need to do any additional works. Picasso and Glide are a very powerful library for handling images in your app includes. It will read image EXIF data and auto-rotates the images.
Using glide library https://github.com/bumptech/glide
Using Picasso library https://github.com/square/picasso
The code is functionally for landscape and portrait @frontCameraID = variable got it the method classic for show camera wanted
Method for get orientation y rotation to save picture and display orientation @result = orientation on the preview view of camera @rotationPicture = rotation necessary to save picture correctly
Someone question about code, please tell me.
I just encountered the same issue, and used this to correct the orientation:
If the width of the Bitmap is greater than the height, the returned image is in landscape, so I rotate it 90 degrees.
Hope it helps anyone else with this issue.
I hope this will help.Thanks!