我使用相机拍照后使用com.android.camera.action.CROP进行裁剪.
下面是我之前在4.3之前工作的代码.
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setType("image/*");
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
cropIntent.putExtra("outputX", Conf.getInt("IMAGE_WIDTH"));
cropIntent.putExtra("outputY", Conf.getInt("IMAGE_HEIGHT"));
cropIntent.putExtras(extras);
startActivityForResult(cropIntent, CROP_REQUEST_CODE);
Run Code Online (Sandbox Code Playgroud)
但是现在,由于android裁剪操作会将您带到图库(因为图库默认为裁剪),因此裁剪方法失败(照片未保存到图库).
有没有人知道解决这个问题的方法.我可以在相机拍摄的照片上使用裁剪
复制前面提到的类似问题的答案..
您是否考虑过使用像这样的库:
我发现com.android.camera.action.CROP有时可能会因手机而异,但并不总是可用,所以如果你想发布它,它可能会给你带来一些问题.
更新:
我用Android 4.3测试了上面的库,它没有问题.您只需将库添加到项目中即可.
然后,您可以以非常类似的方式编写方法:
private void performCrop(Uri picUri) {
//you have to convert picUri to string and remove the "file://" to work as a path for this library
String path = picUri.toString().replaceAll("file://", "");
try {
int aspectX = 750;
int aspectY = 1011;
Intent intent = new Intent(this, CropImage.class);
//send the path to CropImage intent to get the photo you have just taken or selected from gallery
intent.putExtra(CropImage.IMAGE_PATH, path);
intent.putExtra(CropImage.SCALE, true);
intent.putExtra("aspectX", aspectX);
intent.putExtra("aspectY", aspectY);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(mCurrentPhotoPath)));
startActivityForResult(intent, CROP);
}
catch (ActivityNotFoundException anfe) {
String errorMessage = "Your device doesn't support the crop action!";
Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
toast.show();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18210 次 |
| 最近记录: |