问题描述
在我的应用程序要求中,从图库中选择图像,然后裁剪所选图像并设置为imageview.下面是我用于裁剪图像的示例代码.
In my application requirement is select the image from gallery and then crop the selected image and set to the imageview. Below is my sample code for cropping the image.
//call the standard crop action intent (the user device may not support it)
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setClassName("com.android.camera", "com.android.camera.CropImage");
//indicate image type and Uri
cropIntent.setDataAndType(mImageCaptureUri, "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);
cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageCaptureUri);
cropIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
//start the activity - we handle returning in onActivityResult
startActivityForResult(cropIntent, PIC_CROP);
上面的代码在android棉花糖的设计下工作正常,但是android marsh mallow崩溃了.如何解决这个问题?
Above code is works fine in below android marshmallow devises but android marsh mallow it is crashing.How to solve the issue?
推荐答案
通过裁剪实现相机和图库的最简单方法是使用library.在市场上,有太多可用的第三方库,但它们都不适合所有人设备.有一个可用的库,该库在不同的设备和多家公司的设备中都稳定. https://github.com/biokys/cropimage 使用此演示.这是一个非常老的库,但是在所有不同的设备上都稳定.
The easiest way to implement camera and gallery with cropping is to use library.in market there are so many third party library are available but none of them work for all devices.There is one library is available which is stable across the deferent and several companies devices.https://github.com/biokys/cropimage use this demo.This is very old library but it is stable across the all different devices.
这篇关于如何通过使用默认裁剪意图在android棉花糖中裁剪图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!