[英]How to crop the image data before saving the in gallery?
完成捕获图像后,您将获得比较麻烦的图像路径或存储在onActivityResult()
中获得的位图以进行捕获。
现在,使用下面的代码执行该图像的裁剪:
public void performCrop(){
//call the standard crop action intent (the user device may not support it)
Intent cropIntent = new Intent("com.android.camera.action.CROP");
//indicate image type and Uri
cropIntent.setDataAndType(picUri, "image/*");
//set crop properties
cropIntent.putExtra("crop", "true");
//indicate aspect of desired crop
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
//indicate output X and Y
cropIntent.putExtra("outputX", 256);
cropIntent.putExtra("outputY", 256);
//retrieve data on return
cropIntent.putExtra("return-data", true);
//start the activity - we handle returning in onActivityResult
startActivityForResult(Intent.createChooser(cropIntent,"Cropping"), PIC_CROP);
}
现在,再次在onActivityResult()
内部匹配您的PIC_CROP
请求代码,并得到如下结果图像:
//get the returned data
Bundle extras = data.getExtras();
//get the cropped bitmap
Bitmap thePic = extras.getParcelable("data");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.