-2

This is Image capture by Standard Camera and open by Gallery of Android

enter image description here

This is Image capture by My App Camera and open by Gallery of Android enter image description here

How set Orientation Hint of file Image(It can display the same Standard Camera)?

I try with setRotation of Camera, But it not working:

Camera.Parameters parameters = mCamera.getParameters();
parameters.setRotation(rotation);
mCamera.setParameters(parameters);

If record video i use: MediaRecorder.setOrientationHint(rotation); But Image i don't know. Can you help me?

Community
  • 1
  • 1
mum
  • 1,637
  • 11
  • 34
  • 58

2 Answers2

1

You need to implement your own photo capture activity for getting the desired orientation for every image capture on every device.

I've implemented one capture activity which you can take the photo and set the orientation of the photo. You can check out my answer about rotation of images on this topic:

implementation:

Camera capture orientation on samsung devices in android

saving the photo functions additional to my answer I gave above:

savePhoto function:

public void savePhoto(Bitmap bmp) {

        imageFileFolder = new File(Environment.getExternalStorageDirectory(),
                cc.getDirectoryName());
        imageFileFolder.mkdir();
        FileOutputStream out = null;
        Calendar c = Calendar.getInstance();
        String date = fromInt(c.get(Calendar.MONTH))
                + fromInt(c.get(Calendar.DAY_OF_MONTH))
                + fromInt(c.get(Calendar.YEAR))
                + fromInt(c.get(Calendar.HOUR_OF_DAY))
                + fromInt(c.get(Calendar.MINUTE))
                + fromInt(c.get(Calendar.SECOND));
        imageFileName = new File(imageFileFolder, date.toString() + ".jpg");
        try {
            out = new FileOutputStream(imageFileName);
            bmp.compress(Bitmap.CompressFormat.JPEG, 70, out);
            out.flush();
            out.close();
            scanPhoto(imageFileName.toString());
            out = null;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

scanPhoto function:

public void scanPhoto(final String imageFileName) {
        geniusPath = imageFileName;
        msConn = new MediaScannerConnection(MyClass.this,
                new MediaScannerConnectionClient() {
                    public void onMediaScannerConnected() {
                        msConn.scanFile(imageFileName, null);

                    }

                    @Override
                    public void onScanCompleted(String path, Uri uri) {

                        msConn.disconnect();

                    }
                });
        msConn.connect();
    }

SavePhotoTask class:

class SavePhotoTask extends AsyncTask<byte[], String, String> {
        @Override
        protected String doInBackground(byte[]... jpeg) {
            File photo = new File(Environment.getExternalStorageDirectory(),
                    "photo.jpg");
            if (photo.exists()) {
                photo.delete();
            }
            try {
                FileOutputStream fos = new FileOutputStream(photo.getPath());
                fos.write(jpeg[0]);
                fos.close();
            } catch (java.io.IOException e) {
            }
            return (null);
        }
    }
Community
  • 1
  • 1
canova
  • 3,965
  • 2
  • 22
  • 39
  • Why Standard Camera open by Gallery, It can display orientation the same image preview captured. And original not change – mum Apr 21 '14 at 13:18
  • If rotation image after capture, i had know. I want to keep original image ( the same standard camera) – mum Apr 21 '14 at 13:20
  • What I am telling is, in my answer you will have full control of taking a photo, saving it with correct orientation as the picture taken, and see it correctly in phone's own gallery. – canova Apr 21 '14 at 13:20
  • You look demo of Standard camera. Original Image not change – mum Apr 21 '14 at 13:22
  • your original image? you can save 2 copies if you want to keep the wrong oriented one, and show the correct oriented in the gallery but I didn't get what you mean. By rotating it programmatically nothing happens to your image and you can use it on every device. – canova Apr 21 '14 at 13:23
  • My Original Image the same original image of Standard camera. If after capture Image, We will rotation image , proccess very low – mum Apr 21 '14 at 13:26
  • no offense but I can't exactly understand what you are trying to say. If you are talking about quality by telling "process low", you can save with high resolution after rotation. It is up to you how you create your bitmap. – canova Apr 21 '14 at 13:35
  • and since you can't manipulate the original image, I've implemented this way so I wrote my own photo take class. Can't help you any further this is the most accurate and precise way – canova Apr 21 '14 at 13:38
  • Can to set TAG_ORIENTATION to file? – mum Apr 21 '14 at 13:41
  • it is the original orientation of the file. I get it, and then rotate it to show as the same angle as the photo is taken – canova Apr 21 '14 at 13:44
0

The cause: my app can't rotation when open file by Gallery of Android, because i create file has ext .png, If i change ext to .jpg, It can display OK.

mum
  • 1,637
  • 11
  • 34
  • 58