从此 Android 裁剪图像库输出 Uri?
Output Uri from this Android crop image library?
我正在尝试在我的应用中实施 SoundCloud's image crop。这是我目前所做的:
调用Crop.pickImage((Activity) this)
选择图片
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == Crop.REQUEST_PICK && resultCode == RESULT_OK) {
Uri inputUri = data.getData();
new Crop(inputUri).output(outputUri).asSquare().start((Activity) context);
}
else if (requestCode == Crop.REQUEST_CROP && resultCode == RESULT_OK) {
Uri cropped = data.getData();
}
}
此时我不知道 outputUri
应该是什么。我可以只使用相同的 inputUri
作为输出,但这会覆盖原始图像文件。我想创建一个新文件。但我无法创建新的 Uri,因为 Android Studio 告诉我新初始化的 Uri 是抽象的,无法使用。
我也使用以下方法为我的裁剪图像库创建 URI。希望对您有所帮助:
private void fileSaving(){
String stateEnvironment = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(stateEnvironment)) {
mFileTemp = ChatUtils.getOutputMediaFile(101);//new File(Environment.getExternalStorageDirectory(), TEMP_PHOTO_FILE_NAME);
} else {
mFileTemp = new File(getFilesDir(), sTEMP_PHOTO_FILE_NAME);
}
}
private void takePicture() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
try {
Uri mImageCaptureUri = null;
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
mImageCaptureUri = Uri.fromFile(mFileTemp);
} else {
// mImageCaptureUri =
// InternalStorageContentProvider.CONTENT_URI;
}
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
mImageCaptureUri);
intent.putExtra("return-data", true);
startActivityForResult(intent, mREQUEST_CODE_TAKE_PICTURE);
} catch (ActivityNotFoundException e) {
}
}
我正在尝试在我的应用中实施 SoundCloud's image crop。这是我目前所做的:
调用Crop.pickImage((Activity) this)
选择图片
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == Crop.REQUEST_PICK && resultCode == RESULT_OK) {
Uri inputUri = data.getData();
new Crop(inputUri).output(outputUri).asSquare().start((Activity) context);
}
else if (requestCode == Crop.REQUEST_CROP && resultCode == RESULT_OK) {
Uri cropped = data.getData();
}
}
此时我不知道 outputUri
应该是什么。我可以只使用相同的 inputUri
作为输出,但这会覆盖原始图像文件。我想创建一个新文件。但我无法创建新的 Uri,因为 Android Studio 告诉我新初始化的 Uri 是抽象的,无法使用。
我也使用以下方法为我的裁剪图像库创建 URI。希望对您有所帮助:
private void fileSaving(){
String stateEnvironment = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(stateEnvironment)) {
mFileTemp = ChatUtils.getOutputMediaFile(101);//new File(Environment.getExternalStorageDirectory(), TEMP_PHOTO_FILE_NAME);
} else {
mFileTemp = new File(getFilesDir(), sTEMP_PHOTO_FILE_NAME);
}
}
private void takePicture() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
try {
Uri mImageCaptureUri = null;
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
mImageCaptureUri = Uri.fromFile(mFileTemp);
} else {
// mImageCaptureUri =
// InternalStorageContentProvider.CONTENT_URI;
}
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
mImageCaptureUri);
intent.putExtra("return-data", true);
startActivityForResult(intent, mREQUEST_CODE_TAKE_PICTURE);
} catch (ActivityNotFoundException e) {
}
}