Always do resize operation on background thread

This commit is contained in:
Naveen 2023-05-24 03:48:16 +05:30
parent 2919b36583
commit 388037f6b5
No known key found for this signature in database
GPG key ID: 0E155DAD31671DA3

View file

@ -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)
} }
} }
} }