2

I have an application that uses the camera API, not camera2, and it works great. Here is what I am doing (1) You capture a photo with the camera API using the takePicture(null, null, mPictureCallback) method. (2) The byte[] data array is converted into a Bitmap and is put on the screen in the callback

I have set the picture size and the preview size in my camera parameters. I am hoping to have something similar to Snapchat. Where you take a photo and it scales to every screen without distortion or cropping. How is this possible?

  • It doesn't seem theoretically possible to fit the same image without distortion and cropping to every screen. Take for example the 1440 x 1440 pixels Blackberry Passport and 800 x 480 pixels Galaxy S. – Alex Cohn Jan 26 '16 at 22:25

1 Answers1

0

Possibly you are rotating the matrix of the image before save it. that's why the image it´s stretched, don´t rotate the matrix and just save the correct value of orientation in the ExifInterface. Try to use something like this with your image:

ExifInterface exif=new ExifInterface(pictureFile.toString());

    Log.d("EXIF value", exif.getAttribute(ExifInterface.TAG_ORIENTATION));
    if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("6")){
        realImage= rotate(realImage, 90);
    } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("8")){
        realImage= rotate(realImage, 270);
    } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("3")){
        realImage= rotate(realImage, 180);
    } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("0")){
        realImage= rotate(realImage, 45);
    }

Other way it´s that your Byte Array it´s already saved with a wrong Orientation, in that case you must go to your code and check which parameter are you using when you create your ContentBuilder, check your MediaService parameter:`

MediaStore.Images.ImageColumns.ORIENTATION

Finally I had a similar problem but not with the saved image, it was with the camera preview, the problem appear when I didn't reset my camera session, so the buffer have a different size. Check the post, maybe it will help you with the solution or the code to resize the image.

Camera PreviewView is stretched in some Android devices

halfer
  • 19,824
  • 17
  • 99
  • 186
Francisco Durdin Garcia
  • 12,540
  • 9
  • 53
  • 95