Android-图片调整大小和裁剪

时间:2015-05-13 13:09:29

标签: android image resize crop

我正在使用图书馆从图库中选择图像并裁剪它。但是,我找到了旋转图像的选项。 Here's the link 到我正在使用的图书馆。

在我的代码中,我正在访问提供的功能,类似于库中给出的示例。我有两个问题。

  1. 我从画廊中选择的图像总是在搜索解决方案时以某种顺序(时钟或反时钟)旋转我明白这是由于图像的大尺寸造成的。但是,由于我必须使用这个库,因此无法找到调整图像大小的好方法。

  2. 虽然图像旋转工作正常,但我能够正确裁剪图像,但生成的裁剪图像仍然会旋转,裁剪的部分相当于我裁剪的部分。抱歉,由于回购积分较少,我无法发布图片。

  3. 由于

2 个答案:

答案 0 :(得分:0)

您可以使用此功能来确定图库中图像的旋转。您需要将路径传递给您从选择器返回的图像。

public static int getRotationFromBitmapFile(String filePath) {
        ExifInterface exifInterface = null;
        try {
            exifInterface = new ExifInterface(filePath);
        } catch (IOException e) {
            //Logger.d("Unable to read ExifInterface from file", e);
        }

        if (exifInterface != null) {
            int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);
            switch (orientation) {
                case ExifInterface.ORIENTATION_ROTATE_180:
                    return 180;
                case ExifInterface.ORIENTATION_ROTATE_270:
                    return 270;
                case ExifInterface.ORIENTATION_ROTATE_90:
                    return 90;
                case ExifInterface.ORIENTATION_NORMAL:
                    return 0;
            }
        }

        //Could not read or information not present, use 0?!!
        return 0;
    }

答案 1 :(得分:0)

好的,所以我找不到任何简单的方法来做到这一点。 但是我在git上有一个旧的存储库(release notes)并调整了一点以获得我想要的东西。我调整了宽高比和布局设计,使它看起来很棒!

感谢您的帮助。

相关问题