Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed incorrect callbacks when images fail to be saved #856

Open
wants to merge 1 commit into
base: develop-non-native
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private void copyExifForOutputFile(Context context) throws IOException {
}
}

private void saveImage(@NonNull Bitmap croppedBitmap) {
private void saveImage(@NonNull Bitmap croppedBitmap) throws IOException {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your PR description does not match the changes you have made, would you like to elaborate on the issue?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When introduced to a nonexistent path, will throw FileNotFoundException, at this point in the onPostExecute method, should the callback mCropCallback#OnCropFailure method, But the actual callback mCropCallback#onBitmapCropped method

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@liujingxing is this code working properly? could you please add a crop from camera feature?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public class TestActivity extends AppCompatActivity {

    private void crop(File srcFile) {
        String cropPath = getExternalCacheDir() + "/image/test.jpg";
        File cropFile = new File(cropPath);
        File parentFile = cropFile.getParentFile();
        //is false,The BitmapCropTask#saveImage method will throw a FileNotFoundException
        boolean exists = parentFile.exists(); 
        UCrop.of(Uri.fromFile(srcFile), Uri.fromFile(cropFile))
            .withAspectRatio(1, 1)
            .withMaxResultSize(800, 800)
            .start(this);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (requestCode == UCrop.REQUEST_CROP) {
                Uri uri = UCrop.getOutput(data);
                File cropFile = new File(uri.getPath());
                boolean exists = cropFile.exists(); // Actual false, expected true
            }
        } else if (resultCode == UCrop.RESULT_ERROR) {
            //FileNotFoundException occurred and should be called back here
            Throwable throwable = UCrop.getError(data);
        }
    }
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a example project of opening camera and the taking picture and then crop?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opening the camera to take photos is the same problem. Note that the problem is not srcFile, but corpFileparent directory does not exist

Context context = mContext.get();
if (context == null) {
return;
Expand All @@ -220,6 +220,7 @@ private void saveImage(@NonNull Bitmap croppedBitmap) {
croppedBitmap.recycle();
} catch (IOException exc) {
Log.e(TAG, exc.getLocalizedMessage());
throw exc;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The saveImage method should throw exceptions, not just log them

} finally {
BitmapLoadUtils.close(outputStream);
BitmapLoadUtils.close(outStream);
Expand Down