Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ACTION_IMAGE_CAPTURE orientation problem on Nexus S and Samsung Galaxy S I9000

I'm trying to shoot picture and store it into internal storage by using the following code:

Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
takenPhoto = new File(uploadsFolder, getNewPicFileName());
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(takenPhoto));
startActivityForResult(intent, SHOOT_MEDIA_REQUEST_CODE);

The problem is that on Nexus S and Galaxy S devices default and the single orientation for ACTION_IMAGE_CAPTURE intent is landscape. If i shoot picture in portrait mode, that picture is stored into "takenPhoto" file rotated.

That problem seems appearing only on Samsung Galaxy S devices (Galaxy S and Nexus S), another devices i tried make auto-rotate depending on orientation during image shooting.

I will very appreciate any help on that issue.

like image 527
Alexander Bezverhni Avatar asked May 26 '11 18:05

Alexander Bezverhni


1 Answers

From what I can tell, this is happening because the MediaStore.Images.ImageColumns.ORIENTATION value isn't being set by this Intent. It does get set when things come through the normal camera app.

On my Nexus S, however, the file still gets the correct EXIF data. So you could get the orientation like this:

ExifInterface exif = new ExifInterface("filepath");
exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                     ExifInterface.ORIENTATION_NORMAL);

Then you could use use ContentResolver.update add the correct ORIENTATION data. You just need to translate the ExifInterface orientation options to degrees rotated.

Your other option is to create your own Activity to operate the camera hardware and record the file. You'd then keep track of rotations & write the value into the metadata when saving a captured image. Since the Camera app is part of Android, you could probably copy & modify it without too much pain.

like image 107
abscondment Avatar answered Oct 21 '22 14:10

abscondment