のonResumeセクションで
//override method for cropper library
@Override
public void onCropImageComplete(CropImageView view,CropImageView.CropResult result) {
handleCropResult(result, view);
}
private void handleCropResult(CropImageView.CropResult result, CropImageView view)
{
if (result.getError() == null) {
view.setImageBitmap(view.getCroppedImage());
saveImageInGallery(view.getCroppedImage(), String.valueOf(view.getTag()));
Log.i("UriResult", String.valueOf(result.getUri()));
} else {
Log.e("AIC", "Failed to crop image", result.getError());
Toast.makeText(_activity, "Image crop failed: " + result.getError().getMessage(), Toast.LENGTH_LONG).show();
}
}
private void saveImageInGallery(Bitmap bitmap, String imagePath) {
File file = new File(imagePath);
if (file.exists()) {
if (file.delete()) {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri contentUri = Uri.fromFile(file);
mediaScanIntent.setData(contentUri);
_activity.sendBroadcast(mediaScanIntent);
}
}
try {
File mNewFile = new File(imagePath);
FileOutputStream out = new FileOutputStream(mNewFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
bitmap.recycle();
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri contentUri = Uri.fromFile(mNewFile);
mediaScanIntent.setData(contentUri);
_activity.sendBroadcast(mediaScanIntent);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
これは、https://code.tutsplus.com/tutorials/capture-and-crop-animage-with-the-device-camera--mobile-11458 –
あなたが回転のための別のアクティビティに行くのを助けます? –
@masoudvaliはいサー。 – Rajat