我想捕获图像并对其进行裁剪,然后通过改进将该文件发送到服务器。 我尝试以下代码: 意图打开的摄像头
Intent chooserIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File f = new File(Environment.getExternalStorageDirectory(), "POST_IMAGE.jpg");
chooserIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
picUri = Uri.fromFile(f);
startActivityForResult(chooserIntent, REQUEST_CAMERA_IMAGE);
onActivityResult
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CAMERA_IMAGE) {
path = data.getData();
performCrop(path);
}
}
和performCrop方法
private void performCrop(Uri picUri) {
try {
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setDataAndType(picUri, "image/*");
cropIntent.putExtra("crop", true);
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
cropIntent.putExtra("outputX", 300);
cropIntent.putExtra("outputY", 300);
cropIntent.putExtra("return-data", true);
startActivityForResult(cropIntent, PIC_CROP);
} catch (ActivityNotFoundException anfe) {
}
}
但是此代码是错误的!该怎么做?
如果我保存捕获的图像,然后从图库中对其进行裁剪,是否有效?该怎么做?
感谢您的关注。