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
There are two things needed:
Camera preview need the same as your rotation. Set this by
camera.setDisplayOrientation(result);
Save the picture captured as your camera preview. Do this via
Camera.Parameters
.Hope that helps.
There are quite a few similar topics and issues around here. Since you're not writing your own camera, I think it boils down to this:
some devices rotate the image before saving it, while others simply add the orientation tag in the photo's exif data.
I'd recommend checking the photo's exif data and looking particularly for
Since the photo is displaying correctly in your app, i'm not sure where the problem is, but this should definitely set you on the right path!