Как сохранить обрезанное изображение в Android вместо возврата данных обрезки?
У меня есть приложение, в котором я могу позволить пользователю выбрать изображение галереи или сделать снимок с помощью камеры, после чего я даю ему возможность обрезать его.
Теперь, когда пользователь обрезает изображение, обрезатель галереи возвращает ByteArray обрезанной части, можно ли передать параметр, запрашивающий обрезку галереи, сохранить результат в файл (точно так же, как в случае, когда я начинаю намерение захватывать изображение в Верблюд)
например.:
Это код обрезки, который я использую:
// Initialize intent
Intent intent = new Intent("com.android.camera.action.CROP");
// set data type to be sent
intent.setType("image/*");
// get croppers available in the phone
List list = getPackageManager().queryIntentActivities( intent, 0 );
int size = list.size();
// handle the case if there's no cropper in the phone
if (size == 0) {
Toast.makeText(this, "Can not find image crop app", Toast.LENGTH_SHORT).show();
return;
} else {
// now this is the case if cropper exists
// initialize the Uri for the captures or gallery image
Uri imageUri = Uri.fromFile(new File(mCurrentPhotoPath));
// Send the Uri path to the cropper intent
intent.setData(imageUri);
intent.putExtra("outputX", 200);
intent.putExtra("outputY", 200);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("scale", true);
// Here's my attempt to ask the intent to save output data as file
File f = null;
// Here I initialize empty file
try{
// This returns the file created
f = setUpCroppedFile();
mCurrentThumbPath = f.getAbsolutePath();
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
intent.putExtra("output", Uri.fromFile(f));
}
catch(IOException e){
e.printStackTrace();
}
// --------------------------------------------------------------------
// -----------> When changing this to false it worked