Camera capture orientation on samsung devices in android

后端 未结 3 1206
既然无缘
既然无缘 2020-12-05 15:42

I am creating a camera app. The image when captured is shown in the grid view. Now, the code is working completely fine on all the devices except for samsung devices.

<
3条回答
  •  不思量自难忘°
    2020-12-05 16:22

    Here is the code that I used in my app to rotate and works in all devices:

    private Bitmap adjustImageOrientation(Bitmap image) {
            ExifInterface exif;
            try {
                exif = new ExifInterface(picturePath);
                int exifOrientation = exif.getAttributeInt(
                        ExifInterface.TAG_ORIENTATION,
                        ExifInterface.ORIENTATION_NORMAL);
    
                int rotate = 0;
                switch (exifOrientation) {
                case ExifInterface.ORIENTATION_ROTATE_90:
                    rotate = 90;
                    break;
    
                case ExifInterface.ORIENTATION_ROTATE_180:
                    rotate = 180;
                    break;
    
                case ExifInterface.ORIENTATION_ROTATE_270:
                    rotate = 270;
                    break;
                }
    
                if (rotate != 0) {
                    int w = image.getWidth();
                    int h = image.getHeight();
    
                    // Setting pre rotate
                    Matrix mtx = new Matrix();
                    mtx.preRotate(rotate);
    
                    // Rotating Bitmap & convert to ARGB_8888, required by tess
                    image = Bitmap.createBitmap(image, 0, 0, w, h, mtx, false);
    
                }
            } catch (IOException e) {
                     return null;
            }
            return image.copy(Bitmap.Config.ARGB_8888, true);
        }
    

提交回复
热议问题