Why is image rotated when captured by camera?
<p>In my application, I capture an image by camera and save its path in a string variable(SD-card path for sending image on server)  and that time also I set that image on ImageView. But image is automatically rotated in landscape, not set by right angle. I have been searching on StackOverflow and google and find EXIF rotation use this:</p>

<p><a href="http://mobisocial.stanford.edu/news/2011/08/rotating-images-in-android/" rel="nofollow">http://mobisocial.stanford.edu/news/2011/08/rotating-images-in-android/</a></p>

<p>but it is not working. My code is:
        (after croping operation code is of onActivityResult)</p>

<pre><code>case AppConstants.CROP_FROM_CAMERA:
        if (data != null) {
            Bundle extras = data.getExtras();

            if (extras != null) {
                Bitmap photo = extras.getParcelable("data");
                File file = new File("/sdcard/bidnear/");
                if (!file.isDirectory())
                    file.mkdir();
                imageUrl = "/sdcard/bidnear/thumbimgcrop.png";
                file = new File("/sdcard/bidnear/thumbimgcrop.png");
                try {
                    photo = rotateImage(photo,mImageCaptureUri);
                    photo.compress(Bitmap.CompressFormat.PNG, 100,
                            new FileOutputStream(file));
                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                objimg.setBackgroundResource(0);
                objimg.setImageBitmap(photo);

            }
        }
</code></pre>

<p>Rotate method is:</p>

<pre><code>private Bitmap rotateImage(Bitmap objbitmap,Uri uri)
{
    Matrix matrix = new Matrix();
    float rotation =rotationForImage(MyProfile.this, uri);
    if (rotation != 0f) {
         matrix.preRotate(rotation);
    }

    Bitmap resizedBitmap = Bitmap.createBitmap(
            objbitmap, 0, 0,80,80, matrix, true);
    return resizedBitmap;
}
</code></pre>

<p>It is not working; my opening camera and capturing code is:</p>

<pre><code> private void setUserImage() {

    final String[] objimagechooseoptions = new String[] {
            AppConstants.SELECT_CAMERA, AppConstants.SELECT_GALLERY };
    ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this,
            android.R.layout.select_dialog_item, objimagechooseoptions);
    AlertDialog.Builder objbuilder = new AlertDialog.Builder(this);
    objbuilder.setTitle("Select Image");

    objbuilder.setAdapter(adapter, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) { // pick from
                                                                // camera
            if (item == 0) {
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                mImageCaptureUri = Uri.fromFile(new File(Environment
                        .getExternalStorageDirectory(), "tmp_avatar_"
                        + String.valueOf(System.currentTimeMillis())
                        + ".png"));
                intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
                        mImageCaptureUri);
                try {
                    intent.putExtra("return-data", true);
                    startActivityForResult(intent,
                            AppConstants.PICK_FROM_CAMERA);
                } catch (ActivityNotFoundException e) {
                    e.printStackTrace();
                }
            } else { // pick from file
                Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(Intent.createChooser(intent,
                        "Complete action using"),
                        AppConstants.PICK_FROM_FILE);
            }
        }
    });
    final AlertDialog dialog = objbuilder.create();
    dialog.show();
}
</code></pre>
