三星手机无论横竖屏拍照都会横屏发送的问题

关于三星手机的拍照无论横竖屏拍,都会以横屏方式发送出去的问题
首先添加一个判断

   /**
     * 读取照片exif信息中的旋转角度
     * @param path 照片路径
     * @return角度
     */
    public static int readPictureDegree(String path) {
        int degree  = 0;
        try {
            ExifInterface exifInterface = new ExifInterface(path);
            int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
            switch (orientation) {
                case ExifInterface.ORIENTATION_ROTATE_90:
                    degree = 90;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    degree = 180;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_270:
                    degree = 270;
                    break;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return degree;
    }


    public static Bitmap toturn(Bitmap img){
        Matrix matrix = new Matrix();
        matrix.postRotate(+90); /*翻转90度*/
        int width = img.getWidth();
        int height =img.getHeight();
        img = Bitmap.createBitmap(img, 0, 0, width, height, matrix, true);
        return img;
    }

判断图片是否已经发生了旋转
然后在发送之前进行复原,旋转了的话就逆过去旋转回来

 int degree = readPictureDegree("你的图片路径");
                if (degree !=0){
                   bitmap = toturn(bitmap);
                }

你可能感兴趣的:(三星手机无论横竖屏拍照都会横屏发送的问题)