How to change output picture orientation in custom camera app? [Android]

251 views Asked by At

In landscape everything is ok but if I hold the phone vertically the output picture is still in landscape mode. Any help?

I tried using the code this as suggested but the only orientation I get is ORIENTATION_NORMAL no matter how I hold the phone.

ExifInterface ei = new ExifInterface(photoPath);
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION,         ExifInterface.ORIENTATION_NORMAL);

switch(orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
    rotateImage(bitmap, 90);
    break;
case ExifInterface.ORIENTATION_ROTATE_180:
    rotateImage(bitmap, 180);
    break;
// etc.
}

onCreate:

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    View decorView = getWindow().getDecorView();
    i = 0;

    // Hide the status bar.
    int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
    decorView.setSystemUiVisibility(uiOptions);


    // Create an instance of Camera
    mCamera = getCameraInstance();

    //Setparams just sets the focus mode and picture size
    setParams();


    // Create our Preview view and set it as the content of our activity.
    mPreview = new CameraPreview(this, mCamera);
    FrameLayout preview = (FrameLayout)    findViewById(R.id.camera_preview);
    preview.addView(mPreview);


    //Capture click listener
    Button captureButton = (Button) findViewById(R.id.button_capture);
    captureButton.setOnClickListener(
            new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mCamera.takePicture(null,null,mPicture);
                    Log.d("TAG", "Picture 0 taken");
                }
            }
    );


}

onPictureTaken: - The app takes 5 pictures saves them as jpegs one after another and then creates a gif with them in an asyncTask. The only is that it saves all the pictures in landscape mode no matter how you hold the phone.

private Camera.PictureCallback mPicture = new Camera.PictureCallback() {

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

        File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE, i);
        if (pictureFile == null) {
            Log.d(TAG, "Error creating media file, check storage permissions: "
            );
            return;
        }

        try {
            FileOutputStream fos = new FileOutputStream(pictureFile);
            fos.write(data);
            fos.close();
        } catch (FileNotFoundException e) {
            Log.d(TAG, "File not found: " + e.getMessage());
        } catch (IOException e) {
            Log.d(TAG, "Error accessing file: " + e.getMessage());
        }
        i++;

        //starts camera preview after taking picture
        mCamera.startPreview();

        if(i<5){
            mCamera.takePicture(null,null,mPicture);
            Log.d("TAG", "Picture taken" + i);
        }

        if(i==5){
            new asyncGIF().execute();
            i=0;
        }
    }
};
0

There are 0 answers