简体   繁体   中英

Android Camera Preview Image Captured Stretches

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?

Possibly you are rotating the matrix of the image before save it. thats why the image it´s streched, 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 didnt 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 streched in some android devices

Good Luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM