[英]Crop functionality is working on marshmallow or above but do not work below marshmallow
Image is crop and see successfully in List in marshmallow and above but not working below marshmallow. 图片已裁剪,可以在棉花糖及以上的列表中成功查看,但在棉花糖以下则无法正常工作。 I think if we pick google photo for crop than it is working in other scenario its nont working. 我认为,如果我们选择谷歌照片进行裁剪,而不是在其他情况下可以正常工作。
Also in my situation runtime permission is already provided. 同样在我的情况下,已经提供了运行时权限。
Code to click image from camera 代码以单击相机中的图像
Uri fileUri;
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(getExternalCacheDir(), String.valueOf(System.currentTimeMillis()) + ".jpg");
fileUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
startActivityForResult(intent, 501);
@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case 501:
isFromOneActivityToAnother = true;
ImageCropFunction();
//startCropImageActivity(fileUri);
break;
case 502:
uriImageListForServer.add(getImageContentUri(getApplicationContext(), new File((fileUri + "").substring(7, (fileUri + "").length()))));
break;
}
}
public void ImageCropFunction() {
try {
isFromOneActivityToAnother = true;
Intent CropIntent = new Intent("com.android.camera.action.CROP");
CropIntent.setDataAndType(fileUri, "image/*");
CropIntent.putExtra("crop", "true");
CropIntent.putExtra("outputX", 2048);
CropIntent.putExtra("outputY", 2048);
CropIntent.putExtra("scaleUpIfNeeded", true);
CropIntent.putExtra("return-data", true);
startActivityForResult(CropIntent, 502);
} catch (ActivityNotFoundException e) {
}
}
public static Uri getImageContentUri(Context context, File imageFile) {
String filePath = imageFile.getAbsolutePath();
Cursor cursor = context.getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
new String[]{MediaStore.Images.Media._ID},
MediaStore.Images.Media.DATA + "=? ",
new String[]{filePath}, null);
if (cursor != null && cursor.moveToFirst()) {
int id = cursor.getInt(cursor.getColumnIndex(MediaStore.MediaColumns._ID));
cursor.close();
return Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "" + id);
} else {
if (imageFile.exists()) {
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.DATA, filePath);
return context.getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
} else {
return null;
}
}
}
Image is crop and see successfully in List in marshmallow 图片已裁剪,可在棉花糖列表中成功查看
No, it does not. 不,不是的。 It happens to work on the one device that you tested. 它恰好在您测试的一台设备上工作。 Android does not have a CROP
Intent
. Android没有CROP
Intent
。 A few devices might, out of the thousands of devices on the market. 市场上成千上万的设备中可能只有少数设备。
There are many image cropping libraries available for Android . 有许多可用于Android的图像裁剪库 。 Use one. 使用一个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.