2

我们正在开发一个应用程序,允许用户拍照或从图库中挑选一张。我们为此使用了Android Crop库。

在非三星的 Android 设备上进行测试时,照片看起来还不错。但是,在三星设备上拍摄的所有照片都显示为旋转了 90 度。

这里发生了什么?如何使照片以正确的旋转方式显示?

这是一些示例代码。

@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;
    }
4

0 回答 0