Always do resize operation on background thread
This commit is contained in:
parent
2919b36583
commit
388037f6b5
1 changed files with 23 additions and 21 deletions
|
@ -823,33 +823,35 @@ fun BaseSimpleActivity.launchResizeImageDialog(path: String, callback: (() -> Un
|
||||||
}
|
}
|
||||||
|
|
||||||
fun BaseSimpleActivity.resizeImage(path: String, size: Point, callback: (success: Boolean) -> Unit) {
|
fun BaseSimpleActivity.resizeImage(path: String, size: Point, callback: (success: Boolean) -> Unit) {
|
||||||
var oldExif: ExifInterface? = null
|
ensureBackgroundThread {
|
||||||
if (isNougatPlus()) {
|
var oldExif: ExifInterface? = null
|
||||||
val inputStream = contentResolver.openInputStream(Uri.fromFile(File(path)))
|
if (isNougatPlus()) {
|
||||||
oldExif = ExifInterface(inputStream!!)
|
val inputStream = contentResolver.openInputStream(Uri.fromFile(File(path)))
|
||||||
}
|
oldExif = ExifInterface(inputStream!!)
|
||||||
|
}
|
||||||
|
|
||||||
val newBitmap = Glide.with(applicationContext).asBitmap().load(path).submit(size.x, size.y).get()
|
val newBitmap = Glide.with(applicationContext).asBitmap().load(path).submit(size.x, size.y).get()
|
||||||
|
|
||||||
val newFile = File(path)
|
val newFile = File(path)
|
||||||
val newFileDirItem = FileDirItem(path, path.getFilenameFromPath())
|
val newFileDirItem = FileDirItem(path, path.getFilenameFromPath())
|
||||||
getFileOutputStream(newFileDirItem, true) { out ->
|
getFileOutputStream(newFileDirItem, true) { out ->
|
||||||
if (out != null) {
|
if (out != null) {
|
||||||
out.use {
|
out.use {
|
||||||
try {
|
try {
|
||||||
newBitmap.compress(newFile.absolutePath.getCompressionFormat(), 90, out)
|
newBitmap.compress(newFile.absolutePath.getCompressionFormat(), 90, out)
|
||||||
|
|
||||||
if (isNougatPlus()) {
|
if (isNougatPlus()) {
|
||||||
val newExif = ExifInterface(newFile.absolutePath)
|
val newExif = ExifInterface(newFile.absolutePath)
|
||||||
oldExif?.copyNonDimensionAttributesTo(newExif)
|
oldExif?.copyNonDimensionAttributesTo(newExif)
|
||||||
|
}
|
||||||
|
} catch (ignored: Exception) {
|
||||||
}
|
}
|
||||||
} catch (ignored: Exception) {
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(true)
|
callback(true)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
callback(false)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
callback(false)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue