0

I'm doing an app, that needs the device(usually a tablet) to be in landscape, but the picture has to be shown in portrait in the screen.

Until here, I have done it. Bu now, when I take a picture the "preview" image, is showed in landsacape and looks very strange.

See image to see what I mean:

How you see before take image: enter image description here

And thats after take picture: enter image description here

And I don't know how to fix it

Thats surfaceView:

@Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

        // stop Preview Before making changes
        try {
            mCamera.stopPreview();
        } catch (Exception e) {
            // ignored: is trying to stop a non-existent preview

        }

        try {
            mCamera.setPreviewDisplay(mHolder);
            mCamera.startPreview();
        } catch (Exception e) {
            Log.d("CAMERAPREVIEW", "Error starting camera preview : " + e.getMessage());
        }

    }

And the method overrided

private PictureCallback mPicture = new PictureCallback() {

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

            File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
            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();

//                              Not used for the moment
//              Intent returnIntent = new Intent();
//              setResult(RESULT_CANCELED, returnIntent);
//              finish();
            } catch (FileNotFoundException e) {
                Log.d(TAG, "File not found: " + e.getMessage());
            } catch (IOException e) {
                Log.d(TAG, "Error accessing file: " + e.getMessage());
            }
        }
    };
Shudy
  • 7,806
  • 19
  • 63
  • 98

1 Answers1

0

You can use Camera.setDisplayOrientaion() to rotate the preview on the SurfaceView. But this does not effect the captured image. Your post does not reveal how you display the captured image from file (I assume this is what you show in the second picture). If you load it as a bitmap into an ImageView, you can request rotation for the bitmap.

It also looks like your picture dimensions have different aspect ratio from the preview. I suggest that you look at a recent discussion here.

But maybe I misunderstand what you are doing. Maybe your problem is that you don't restart preview in onPicturetaken()?

Community
  • 1
  • 1
Alex Cohn
  • 56,089
  • 9
  • 113
  • 307