Image Orientation automatically changed while setting in image view in android
<p>I have a problem that when  I am clcking an image from the camera in my app, it is in portrait mode, and image is clicked in portrait mode. But when I am setting the same image in image view then its orientation will automatically changed to landscape. I don't know Why it responds like that because Camera already in Portrait mode.</p>

<p><strong>My Code for Taking Picture from Custom Camera:</strong></p>

<pre><code>package com.irant.cameraApplication;

import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.app.Activity;
import android.hardware.Camera;
import android.hardware.Camera.CameraInfo;
import android.hardware.Camera.PictureCallback;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.Environment;
import android.provider.SyncStateContract.Constants;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;

import com.irant.a1techno.R;
import com.irant.a1techno.SignupDetails;




public class Irant_Custom_cameraApplication extends Activity implements Callback {

    private Camera irantCamera;
    MediaRecorder mediaRecorder;
    ImageButton btn_cameraClick,btn_wrongTick,btn_rightTick,btn_toggleCamera;
    int cameraId=-1;
    File picture_file;
    String photo_FileName,photo_file;

    @Override
    public void onCreate(Bundle savedInstanceState){

        super.onCreate(savedInstanceState);
        setContentView(R.layout.custom_camera);

        SurfaceView surfaceView = (SurfaceView)findViewById(R.id.surfaceView);
        SurfaceHolder surfaceholder = surfaceView.getHolder();
        surfaceholder.addCallback(this);
        surfaceholder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        surfaceholder.setFixedSize(300, 300);


        //Capturing the photo
        btn_cameraClick = (ImageButton)findViewById(R.id.btn_cameraClick);
        btn_cameraClick.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub

                irantCamera.takePicture(null, null, jpegCallback);

            }
        });

        btn_wrongTick = (ImageButton)findViewById(R.id.btn_wrongTick);
        btn_wrongTick.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {

                //to start the camera preview again..
                irantCamera.startPreview();

            }
        });



        btn_rightTick = (ImageButton)findViewById(R.id.btn_rightTick);
        btn_rightTick.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {

                //getting the image from the sdcard
                finish();

            }
        });

        btn_toggleCamera = (ImageButton)findViewById(R.id.btn_frontBackCamera);
        btn_toggleCamera.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub

                findFrontFacingCamera();

                if(cameraId&gt;0){

                    Toast.makeText(getApplicationContext(), "Front Camera Available", Toast.LENGTH_SHORT).show();

                    //irantCamera = Camera.open(cameraId);
                    /*  irantCamera = Camera.open(cameraId);
                    irantCamera.setDisplayOrientation(90);
                    irantCamera.startPreview();*/

                }

                else{

                    Toast.makeText(getApplicationContext(), "Front Camera Not Available", Toast.LENGTH_SHORT).show();

                }


            }
        });
    }



    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width,
            int height) {
        // TODO Auto-generated method stub


    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        // TODO Auto-generated method stub

        if(mediaRecorder==null){

            try{
                irantCamera = Camera.open();
                irantCamera.setPreviewDisplay(holder);
                irantCamera.setDisplayOrientation(90);
                irantCamera.startPreview();
            }
            catch (Exception e) {
                // TODO: handle exception
                Log.d("Error opening", e.getMessage());
            }

        }

    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        // TODO Auto-generated method stub

        irantCamera.stopPreview();
        irantCamera.release();

    }


    //used to save the image in sdCard directory
    //don't forget to give the WRITE_EXTERNAL_STORAGE PERMISSION

    PictureCallback jpegCallback = new PictureCallback() {



        @Override
        public void onPictureTaken(byte[] data, Camera camera) {

            //here we write the code for saving the picture onto the sdCard


            File pictureFileDir = getDir();

            //to check whether directory exists or not!!
            if (!pictureFileDir.exists() &amp;&amp; !pictureFileDir.mkdirs()) {

                //Log.d(Constants.DEBUG_TAG, "Can't create directory to save image.");
                Toast.makeText(Irant_Custom_cameraApplication.this, "Can't create directory to save image.",
                        Toast.LENGTH_LONG).show();
                return;

            }

            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyymmddhhmmss");
            String date = dateFormat.format(new Date());
            photo_file="Picture_"+date+".jpg";

            photo_FileName = pictureFileDir.getPath()+File.separator+photo_file;

            picture_file = new File(photo_FileName);

            FileOutputStream outStream = null;
            try{
                Toast.makeText(getApplicationContext(), "Image captured!", Toast.LENGTH_LONG).show();
                outStream = new FileOutputStream(picture_file);
                outStream.write(data);
                outStream.close();

                String imgpath = photo_file;
                System.out.println("Path for the image*********************"+photo_file);
                SignupDetails.imagePath=imgpath;

            }


            catch (Exception e) {

                Log.d("Image save error :", e.getMessage());    
            }
        }
    };

    private int findFrontFacingCamera() {
        cameraId = -1;
        // Search for the front facing camera
        int numberOfCameras = Camera.getNumberOfCameras();
        for (int i = 0; i &lt; numberOfCameras; i++) {
            CameraInfo info = new CameraInfo();
            Camera.getCameraInfo(i, info);
            if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
                //Log.d(DEBUG_TAG, "Camera found");
                cameraId = i;
                break;
            }
        }
        return cameraId;
    }

    private File getDir() {
        File sdDir = Environment
        .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
        return new File(sdDir, "IrantCamera");
    }
}
</code></pre>
