它打开了“从画廊中选择”选项,但我不想要这个。我想直接在图像上显示裁剪选项。我已经使用了意图
// Crop.java
private String defaultImagePath;
final int PIC_CROP = 1;
private Uri mCropImagedUri;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.crop);
cropImage = (ImageView) this.findViewById(R.id.imageView4);
seekBarCrop = (SeekBar) findViewById(R.id.seekBarCrop);
Bundle b = getIntent().getExtras();
String imagePath = b.getString("imagePath");
defaultImagePath = imagePath;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 1;
bitmap = BitmapFactory.decodeFile(imagePath, options);
cropImage.setImageBitmap(bitmap);
cropImageActivity(defaultImagePath, cropImage);
}
private void cropImageActivity(String path, View cropImage) {
try {
mCropImagedUri = Uri.parse(path);
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setDataAndType(mCropImagedUri, "image/*");
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
cropIntent.putExtra("scale", true);
cropIntent.putExtra("outputX", 500);
cropIntent.putExtra("outputY", 500);
cropIntent.putExtra("return-data", false);
// start the activity - we handle returning in onActivityResult
startActivityForResult(cropIntent, PIC_CROP);
} catch (ActivityNotFoundException anfe) {
// display an error message
String errorMessage = "Whoops - your device doesn't support the crop action!";
Toast toast = Toast
.makeText(this, errorMessage, Toast.LENGTH_SHORT);
toast.show();
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PIC_CROP) {
if (data != null) {
// get the returned data
Bundle extras = data.getExtras();
// get the cropped bitmap
Bitmap selectedBitmap = extras.getParcelable("data");
cropImage.setImageBitmap(selectedBitmap);
}
}
}