我想张贴一张照片作为imageButton,但在发布之前我有一个裁剪器
private void CropImage() {
try {
CropIntent = new Intent("com.android.camera.action.CROP");
CropIntent.setDataAndType(uri, "image/*");
CropIntent.putExtra("crop", "true");
CropIntent.putExtra("outputX", 180);
CropIntent.putExtra("outputY", 180);
CropIntent.putExtra("aspectX", 3);
CropIntent.putExtra("aspectY", 4);
CropIntent.putExtra("scaleUpIfNeeded", true);
CropIntent.putExtra("return-data", true);
startActivityForResult(CropIntent , 1);
}
catch (ActivityNotFoundException ex){
}
}
当我从画廊中选择一张照片或用我的相机拍照时,它会显示一个干杯。此图片不支持编辑,我不确定是什么原因造成的。
这是我的GalleryOpen()和CameraOpen()
private void GalleryOpen() {
GalleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(Intent.createChooser(GalleryIntent, "Select Images From Gallery"), 2);
}
private void CameraOpen() {
CamIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
file = new File(Environment.getExternalStorageDirectory(),
"file"+String.valueOf(System.currentTimeMillis())+ ".jpg");
uri = FileProvider.getUriForFile(getActivity(), BuildConfig.APPLICATION_ID + ".provider", file);
CamIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
CamIntent.putExtra("return-data", true);
CamIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivityForResult(CamIntent, 0);
}
我的OnActivityResult
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 0 && resultCode == RESULT_OK)
CropImage();
else if(requestCode == 2) {
if (data != null) {
uri = data.getData();
CropImage();
}
}
else if(requestCode == 1) {
if(data != null){
Bundle bundle = data.getExtras();
Bitmap bitmap = bundle.getParcelable("data");
imageHolder.setImageBitmap(bitmap);
}
}
}