-
Notifications
You must be signed in to change notification settings - Fork 4
Crop Image Intent
Roman Tcaregorodtcev edited this page Apr 19, 2018
·
3 revisions
Pick image for cropping from Gallery or Internet.
// Crop from gallery
OmegaIntentBuilder.from(this)
.cropImage()
.property(DEFAULT_OUTPUT_X, DEFAULT_OUTPUT_Y)
.bitmap(BitmapFactory.decodeResource(getResources(), R.drawable.crop_image))
.createIntentHandler(this)
.failToast("You don't have app for cropping image")
.startActivityForResult(REQUEST_CODE);
// Crop from internet
OmegaIntentBuilder.from(this)
.cropImage()
.property(DEFAULT_OUTPUT_X, DEFAULT_OUTPUT_Y)
.fileUrlWithMimeType("https://avatars1.githubusercontent.com/u/28600571?s=200&v=4", MimeTypes.IMAGE_PNG)
.download(new DownloadCallback() {
@Override
public void onDownloaded(boolean success, @NotNull ContextIntentHandler contextIntentHandler) {
hideProgress();
startActivityForResult(contextIntentHandler.getIntent(), REQUEST_CODE);
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
if (extras != null) {
Bitmap cropped = extras.getParcelable("data");
imageView.setImageBitmap(cropped);
}
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, "Crop cancelled", Toast.LENGTH_SHORT).show();
}
}