fix #643, properly handle saving edited images with file uri

This commit is contained in:
tibbi 2018-02-08 21:11:22 +01:00
parent 316c8fc85d
commit a10fd3e876

View file

@ -144,24 +144,28 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
override fun onCropImageComplete(view: CropImageView, result: CropImageView.CropResult) { override fun onCropImageComplete(view: CropImageView, result: CropImageView.CropResult) {
if (result.error == null) { if (result.error == null) {
if (isCropIntent) { if (isCropIntent) {
var inputStream: InputStream? = null if (saveUri.scheme == "file") {
var outputStream: OutputStream? = null saveBitmapToFile(result.bitmap, saveUri.path)
try { } else {
val stream = ByteArrayOutputStream() var inputStream: InputStream? = null
result.bitmap.compress(CompressFormat.JPEG, 100, stream) var outputStream: OutputStream? = null
inputStream = ByteArrayInputStream(stream.toByteArray()) try {
outputStream = contentResolver.openOutputStream(saveUri) val stream = ByteArrayOutputStream()
inputStream.copyTo(outputStream) result.bitmap.compress(CompressFormat.JPEG, 100, stream)
} finally { inputStream = ByteArrayInputStream(stream.toByteArray())
inputStream?.close() outputStream = contentResolver.openOutputStream(saveUri)
outputStream?.close() inputStream.copyTo(outputStream)
} } finally {
inputStream?.close()
outputStream?.close()
}
Intent().apply { Intent().apply {
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
setResult(RESULT_OK, this) setResult(RESULT_OK, this)
}
finish()
} }
finish()
} else if (saveUri.scheme == "file") { } else if (saveUri.scheme == "file") {
SaveAsDialog(this, saveUri.path, true) { SaveAsDialog(this, saveUri.path, true) {
saveBitmapToFile(result.bitmap, it) saveBitmapToFile(result.bitmap, it)