Skip to content

Instantly share code, notes, and snippets.

@avipars
Created July 17, 2017 14:56
Show Gist options
  • Save avipars/806f59eb6d9be8578fc9d769cf617e48 to your computer and use it in GitHub Desktop.
Save avipars/806f59eb6d9be8578fc9d769cf617e48 to your computer and use it in GitHub Desktop.
Help with getting crop to work
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
assert cursor != null;
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
save.setEnabled(true);
share.setEnabled(false);
}
}
load.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
i.setType("image/*");
// i.putExtra("crop", "true");
// i.putExtra("outputX", 200);
// i.putExtra("outputY", 200);
// i.putExtra("aspectX", 1);
// i.putExtra("aspectY", 1);
// i.putExtra("scale", true);
// i.putExtra(MediaStore.EXTRA_OUTPUT, uriWhereToStore);
// i.putExtra("outputFormat",
// Bitmap.CompressFormat.PNG.toString());
startActivityForResult(i, RESULT_LOAD_IMAGE);
imageLoaded = true;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment