gpt4 book ai didi

Android:从图库加载的位图在 ImageView 中旋转

转载 作者:IT老高 更新时间:2023-10-28 12:59:11 25 4
gpt4 key购买 nike

当我将媒体库中的图像加载到位图中时,一切正常,除了在垂直握住手机时用相机拍摄的照片会被旋转,因此即使出现,我也总是得到水平照片在画廊垂直。为什么会这样?如何正确加载?

最佳答案

所以,举个例子……

首先你需要创建一个ExifInterface:

ExifInterface exif = new ExifInterface(filename);

然后您可以抓取图像的方向:

orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);

以下是方向值的含义: http://sylvana.net/jpegcrop/exif_orientation.html

因此,最重要的值是 3、6 和 8。例如,如果方向是ExifInterface.ORIENTATION_ROTATE_90(即6),你可以像这样旋转图像:

Matrix matrix = new Matrix();
matrix.postRotate(90);
rotatedBitmap = Bitmap.createBitmap(sourceBitmap, 0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight(), matrix, true);

不过,这只是一个简单的例子。我敢肯定还有其他方法可以执行实际旋转。但是您也可以在 StackOverflow 上找到它们。

关于Android:从图库加载的位图在 ImageView 中旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3647993/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com