2

We're developing an app which allows the user to take a photo or pick one from the gallery. We're using the Android Crop library for this.

When testing on Android devices which aren't from Samsung the photo appears okay. However, all photos taken on Samsung devices appear rotated 90 degrees.

What is happening here? How can I make the photos appear in the proper rotation?

Here is some example code.

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data){
        if (resultCode == RESULT_OK) {
            /*if (requestCode == SelectItensOption.MY_SCHOOL.ordinal()) {
                int selectedIndex = data.getIntExtra("selectedIndex",0);
                if (selectedIndex < BusinessModel.getInstance().getSchools().size()){
                    updateSchool(BusinessModel.getInstance().getSchools().get(selectedIndex));
                }
            } else if (requestCode == SelectItensOption.MY_PROFESSION.ordinal()) {
                int selectedIndex = data.getIntExtra("selectedIndex",0);
                if (selectedIndex < BusinessModel.getInstance().getProfessions().size()){
                    updateProfession(BusinessModel.getInstance().getProfessions().get(selectedIndex));
                }
            } else if(requestCode == SelectItensOption.MY_GENDER.ordinal()) {
                int selectedIndex = data.getIntExtra("selectedIndex",0);
                if (selectedIndex == 0) {
                    updateGender(Sex.F);
                } else {
                    updateGender(Sex.M);
                }

            } else */if (requestCode == Crop.REQUEST_PICK) {
                beginCrop(data.getData());
            } else if (requestCode == Crop.REQUEST_CROP) {
                uploadPhoto(Crop.getOutput(data),currentManagePhotoOrder);
            }   else if (requestCode == CODE_CAPTURE_IMAGE) {
                beginCrop(captureImageFileUri);
            } else if (requestCode == SELECTITEM_RESULT_CODE) {
                updateUserInfo();
            }
        }

    }

    private void beginCrop(Uri source) {
        Uri destination = Uri.fromFile(new File(mActivity.getCacheDir(), "image"+currentManagePhotoOrder));
        Crop.of(source, destination).asSquare().start(mActivity);
    }

    @Override
    public void managePhoto(int order) {
        currentManagePhotoOrder = order;
//        captureImageFileUri = FileProvider.getUriForFile(mActivity, mActivity.getApplicationContext().getPackageName() + ".my.package.name.provider", getOutputMediaFile());
//        captureImageFileUri = Uri.fromFile(getOutputMediaFile());
        File photoFile = null;
        try {
            photoFile = createImageFile();
        } catch (IOException ex) {
            // Error occurred while creating the File
            ex.printStackTrace();
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            captureImageFileUri = FileProvider.getUriForFile(mActivity,
                    "com.theluckymountain.spider",
                    photoFile);
        }
        try {
            Photo photo = getUserProfile().getPhotos().get(order-1);

            ManagePhotoPresenter.showAlert(mActivity,photo,captureImageFileUri,(ManagePhotoCallback) this);
        } catch (Exception e) {
            ManagePhotoPresenter.showAlert(mActivity,null,captureImageFileUri,(ManagePhotoCallback)this);
        }

    }

    private File createImageFile() throws IOException {
        // Create an image file name
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String imageFileName = "JPEG_" + timeStamp + "_";
        File storageDir = mActivity.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
        File image = File.createTempFile(
                imageFileName,  /* prefix */
                ".jpg",         /* suffix */
                storageDir      /* directory */
        );

        // Save a file: path for use with ACTION_VIEW intents
//        mCurrentPhotoPath = image.getAbsolutePath();
        return image;
    }
Felipe Ferri
  • 3,488
  • 2
  • 33
  • 48
  • Please provide a [mcve]. That would include code that shows what "using Android Crop" means, along with details of the means by which you are displaying the images. – CommonsWare Apr 16 '18 at 23:34
  • Thank you, I added additional info as you requested. – Felipe Ferri Apr 17 '18 at 00:53
  • 1
    look at this issue https://github.com/jdamcd/android-crop/issues/258. This might help – Ashik Apr 17 '18 at 03:39
  • Thanks for the suggestion, Supto! However, if I rotate manually the photo won't they appear rotated in other devices? – Felipe Ferri Apr 17 '18 at 14:56
  • No, if you rotate the photo on Samsung devices according to Exif flags prior to cropping, this will not effect the photos on devices that store the photo in 'natural' orientation, such as HTC. – Alex Cohn Oct 13 '18 at 13:33

0 Answers0