mirror of
				https://github.com/SimpleMobileTools/Simple-Gallery.git
				synced 2025-06-05 21:59:19 +02:00 
			
		
		
		
	Fix resizeImage() threading issue
				
					
				
			This commit is contained in:
		| @@ -67,18 +67,18 @@ class ResizeMultipleImagesDialog( | ||||
|  | ||||
|     private fun resizeImages(factor: Float) { | ||||
|         progressView.show() | ||||
|         ensureBackgroundThread { | ||||
|             with(activity) { | ||||
|                 val newSizes = imageSizes.map { | ||||
|                     val width = (it.x * factor).roundToInt() | ||||
|                     val height = (it.y * factor).roundToInt() | ||||
|                     Point(width, height) | ||||
|                 } | ||||
|         with(activity) { | ||||
|             val newSizes = imageSizes.map { | ||||
|                 val width = (it.x * factor).roundToInt() | ||||
|                 val height = (it.y * factor).roundToInt() | ||||
|                 Point(width, height) | ||||
|             } | ||||
|  | ||||
|                 val parentPath = imagePaths.first().getParentPath() | ||||
|                 val pathsToRescan = arrayListOf<String>() | ||||
|             val parentPath = imagePaths.first().getParentPath() | ||||
|             val pathsToRescan = arrayListOf<String>() | ||||
|  | ||||
|                 ensureWriteAccess(parentPath) { | ||||
|             ensureWriteAccess(parentPath) { | ||||
|                 ensureBackgroundThread { | ||||
|                     for (i in imagePaths.indices) { | ||||
|                         val path = imagePaths[i] | ||||
|                         val size = newSizes[i] | ||||
|   | ||||
| @@ -823,35 +823,33 @@ fun BaseSimpleActivity.launchResizeImageDialog(path: String, callback: (() -> Un | ||||
| } | ||||
|  | ||||
| fun BaseSimpleActivity.resizeImage(path: String, size: Point, callback: (success: Boolean) -> Unit) { | ||||
|     ensureBackgroundThread { | ||||
|         var oldExif: ExifInterface? = null | ||||
|         if (isNougatPlus()) { | ||||
|             val inputStream = contentResolver.openInputStream(Uri.fromFile(File(path))) | ||||
|             oldExif = ExifInterface(inputStream!!) | ||||
|         } | ||||
|     var oldExif: ExifInterface? = null | ||||
|     if (isNougatPlus()) { | ||||
|         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 newFileDirItem = FileDirItem(path, path.getFilenameFromPath()) | ||||
|         getFileOutputStream(newFileDirItem, true) { out -> | ||||
|             if (out != null) { | ||||
|                 out.use { | ||||
|                     try { | ||||
|                         newBitmap.compress(newFile.absolutePath.getCompressionFormat(), 90, out) | ||||
|     val newFile = File(path) | ||||
|     val newFileDirItem = FileDirItem(path, path.getFilenameFromPath()) | ||||
|     getFileOutputStream(newFileDirItem, true) { out -> | ||||
|         if (out != null) { | ||||
|             out.use { | ||||
|                 try { | ||||
|                     newBitmap.compress(newFile.absolutePath.getCompressionFormat(), 90, out) | ||||
|  | ||||
|                         if (isNougatPlus()) { | ||||
|                             val newExif = ExifInterface(newFile.absolutePath) | ||||
|                             oldExif?.copyNonDimensionAttributesTo(newExif) | ||||
|                         } | ||||
|                     } catch (ignored: Exception) { | ||||
|                     if (isNougatPlus()) { | ||||
|                         val newExif = ExifInterface(newFile.absolutePath) | ||||
|                         oldExif?.copyNonDimensionAttributesTo(newExif) | ||||
|                     } | ||||
|  | ||||
|                     callback(true) | ||||
|                 } catch (ignored: Exception) { | ||||
|                 } | ||||
|             } else { | ||||
|                 callback(false) | ||||
|  | ||||
|                 callback(true) | ||||
|             } | ||||
|         } else { | ||||
|             callback(false) | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user