0

I have an Android app which is capturing an image as a CameraPreview image.
Prior to capturing the image is appears on the Phone screen in Portrait mode (as needed).

But when I do a Save, the image goes to the JPG file rotated to Landscape mode.
I have confirmed this by going to MyFiles, finding the image and viewing it with Gallery - it pops up on-screen in Landscape mode.
Additionally when I upload the image files onto my computer they show up in Landscape mode there as well.
The image is correct, but the orientation is wrong.

The method that I am using to Save is as follows:

private boolean savePhoto(Bitmap bm) {
FileOutputStream image = null;
try {
   image = new FileOutputStream(mLocation);
} catch (FileNotFoundException e) {
   e.printStackTrace();
}
bm.compress(CompressFormat.JPEG, 100, image);
if (bm != null) {
  int h = bm.getHeight();
  int w = bm.getWidth();
} else {
  return false;
}
return true;
}

Can I insert code here or call a routine (if so what code is needed) that can rotate the image into the appropriate orientation prior to the actual Save?

Or is there some other manner to change the resultant JPG image orientation?

POST EDIT - I just now added the following code to examine the Saved JPG file.

ExifInterface exif = new ExifInterface(f.getPath());
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

However it returned an Orientation = 0 which is not telling me that it 'thinks' that the JPG was Saved in Landscape orientation so that I might be able to use other posting's code.

Thanks

Dhugalmac
  • 554
  • 10
  • 20
  • what manufacturer and device is affected by undesire rotation? – Robert Rowntree Aug 20 '15 at 20:24
  • http://stackoverflow.com/questions/14066038/why-image-captured-using-camera-intent-gets-rotated-on-some-devices-in-android may help reviewing this one... – Robert Rowntree Aug 20 '15 at 20:27
  • I am using both Samsung Galaxy S3 & S4 phones for testing and the problem appears in both versions. – Dhugalmac Aug 20 '15 at 20:30
  • if its just 'samsung' rotation issue , then focus on @felix post among answers ( not the accepted answer ) .. and NOTE that 2 diff types of solution exist , operating on 2 diff types of properties. So take the time to measure which error type you actually have before you try to solve it. – Robert Rowntree Aug 20 '15 at 20:39
  • Thank you for your replies. I absolutely agree with: **take time to measure which error type you actually have before you try to solve it** The problem **may** not be just a Samsung issue - its that I only have Samsung development phones to use and they are both exhibiting the problem. I was not aware that there were 2 types of problems/solutions. I'll continue to look over the posted 'solutions' to see if one works - however I haven't been able to get anything working yet. – Dhugalmac Aug 20 '15 at 21:38

0 Answers0