1

Следующий код выводит изображение с камеры требует, но его еще нужно перевернуть. Как это сделать?

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        Log.d("test", "Вход в метод onCreateView()");
        View swipeView = inflater.inflate(R.layout.swipe_fragment, container, false);
        ImageView imageView = (ImageView) swipeView.findViewById(R.id.imageView);
        Bundle bundle = getArguments();
        int position = bundle.getInt("position");
        //imageView.setImageBitmap(decodeSampledBitmapFromFile(mPathFile[position], 990, 742));

        Log.d("test", "Метод onCreateView() position - " + position);
        imageView.setImageBitmap(decodeSampledBitmapFromFile(pathFile.get(position), 990, 742));

        getExifOrientation(pathFile.get(position));

        Log.d("test", "Выход из метода onCreateView()");
        return swipeView;
    }

что в этом методе не так?

public static String getExifOrientation(String filepath) {
        String degree = "0";
        ExifInterface exif = null;
        try {
            exif = new ExifInterface(filepath);
        } catch (IOException ex) {
            Log.e("test", "cannot read exif", ex);
        }
        if (exif != null) {
            int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);
            if (orientation != -1) {
                switch (orientation) {
                    case ExifInterface.ORIENTATION_ROTATE_180:
                        degree = "180";
                        //exif.setAttribute(ExifInterface.TAG_ORIENTATION, "180");
                        break;
                    case ExifInterface.ORIENTATION_ROTATE_90:
                        degree = "90";
                        exif.setAttribute(ExifInterface.TAG_ORIENTATION, "180");

                        break;
                    case ExifInterface.ORIENTATION_ROTATE_270:
                        degree = "270";
                        break;
                }
            }
        }
        //exif.saveAttributes();
        rotate(filepath, degree);
        Log.e("test", "degree - " + degree);
        return degree;

    }

    public static void rotate(String filepath, String degrees) {
        try {
            ExifInterface exif = new ExifInterface(filepath);
            exif.setAttribute(ExifInterface.TAG_ORIENTATION, getExifOrientation(filepath));
            exif.saveAttributes();
        } catch (IOException e) {
            Log.w("test", "cannot set exif data: ");

} }

1 ответ 1

1

Проблема в том, что вы просто перезаписываете метаданные к файлу, а надо поворачивать именно сам bitmap.
Один из вариантов можете посмотреть тут https://stackoverflow.com/questions/9015372/how-to-rotate-a-bitmap-90-degrees

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.