Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从照相机/多媒体资料[Android 9]加载时,图像位图会旋转_Java_Android_Android Camera_Android Bitmap - Fatal编程技术网

Java 从照相机/多媒体资料[Android 9]加载时,图像位图会旋转

Java 从照相机/多媒体资料[Android 9]加载时,图像位图会旋转,java,android,android-camera,android-bitmap,Java,Android,Android Camera,Android Bitmap,我正在从gallery或camera加载图像,以便对其进行编辑。我使用ExiFinInterface来管理位图的旋转。但在三星s8[Android 9]中,它为图像提供90度旋转,但图像最初没有旋转。根据这个旋转,我把它旋转了90度,这是我不想要的 我曾尝试使用ContentResolver通过游标获得旋转,但它也有与ExiFinInterface相同的问题。以下是我尝试解决问题的两种方法: private static int getExifOrientation(String image_a

我正在从gallery或camera加载图像,以便对其进行编辑。我使用ExiFinInterface来管理位图的旋转。但在三星s8[Android 9]中,它为图像提供90度旋转,但图像最初没有旋转。根据这个旋转,我把它旋转了90度,这是我不想要的

我曾尝试使用ContentResolver通过游标获得旋转,但它也有与ExiFinInterface相同的问题。以下是我尝试解决问题的两种方法:

private static int getExifOrientation(String image_absolute_path) throws IOException {
    ExifInterface ei = new ExifInterface(image_absolute_path);
    int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
    switch (orientation) {
        case ExifInterface.ORIENTATION_ROTATE_90:
                return RotationOptions.ROTATE_90;
            case ExifInterface.ORIENTATION_ROTATE_180:
                return RotationOptions.ROTATE_180;
            case ExifInterface.ORIENTATION_ROTATE_270:
                return RotationOptions.ROTATE_270;
            default:
                return RotationOptions.NO_ROTATION;
    }
}

 private static int getOrientation(Context context, Uri photoUri) {
        try {
            Uri imageContentUri = getImageContentUri(context, photoUri.getPath());
            if (imageContentUri == null) {
                return -1;
            }
            Cursor cursor = context.getContentResolver().query(imageContentUri, new String[]{MediaStore.Images.ImageColumns.ORIENTATION}, null, null, null);
            if (cursor == null) {
                return -1;
            }
            if (cursor.getCount() != 1) {
                cursor.close();
                return -1;
            }
            cursor.moveToFirst();
            int orientation = cursor.getInt(0);
            cursor.close();
            cursor = null;
            return orientation;
        } catch (Exception e) {
            return -1;
        }
    }

我也面临着同样的问题。我在没有外部接口的情况下成功了

通过在此条件下旋转图像-

if (bm.getWidth() > bm.getHeight()) {
            bm = rotateImage(bm, 270);
        }
        bm.compress(Bitmap.CompressFormat.JPEG, 100, fos);

我也面临着同样的问题。我在没有外部接口的情况下成功了

通过在此条件下旋转图像-

if (bm.getWidth() > bm.getHeight()) {
            bm = rotateImage(bm, 270);
        }
        bm.compress(Bitmap.CompressFormat.JPEG, 100, fos);

在将图像设置为imageview之前,请尝试使用裁剪图像代码裁剪图像…您的问题是什么?请记住,摄像头应用程序不需要在其捕获的图像中记录准确的EXIF标题。您能提供相关代码吗?由于我无法控制crop作为其第三方库。。。这是一个事实,在我使用裁剪功能后,它得到了正确的方向。@Commonware我想得到图像的正确方向,但在Android 9中无法得到。。它告诉我们图像是旋转的,但它不是。你们有什么证据表明这与Android 9.0有关?您测试了多少不同的Android 9.0设备,来自多少制造商?图像来自何处,您是否手动检查该图像以查看其中包含何种类型的EXIF头?发生这种情况时,请尝试在将图像设置为imageview之前使用裁剪图像代码裁剪图像…您的问题是什么?请记住,摄像头应用程序不需要在其捕获的图像中记录准确的EXIF标题。您能提供相关代码吗?由于我无法控制crop作为其第三方库。。。这是一个事实,在我使用裁剪功能后,它得到了正确的方向。@Commonware我想得到图像的正确方向,但在Android 9中无法得到。。它告诉我们图像是旋转的,但它不是。你们有什么证据表明这与Android 9.0有关?您测试了多少不同的Android 9.0设备,来自多少制造商?图像来自何处?您是否手动检查该图像以查看其中包含何种类型的EXIF头?如果图像实际上是横向的,则会使其成为纵向的。这就是EXIF没有提供正确方向的问题。所以图像旋转会受到影响。如果图像实际上是横向的,它会使其成为纵向的。这就是EXIF不能提供正确方向的问题。因此,图像旋转将受到影响。