-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
base: develop-non-native
Are you sure you want to change the base?
Fixed incorrect callbacks when images fail to be saved #856
Conversation
…d should be callback
@@ -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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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);
}
}
}
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 corpFile
parent directory does not exist
@@ -220,6 +220,7 @@ private void saveImage(@NonNull Bitmap croppedBitmap) { | |||
croppedBitmap.recycle(); | |||
} catch (IOException exc) { | |||
Log.e(TAG, exc.getLocalizedMessage()); | |||
throw exc; |
There was a problem hiding this comment.
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
The image fails to save. The
BitmapCropCallback#onCropFailure
method should be callback