Compressor
Compressor copied to clipboard
FileNotFound Exception When i try to .compressToFile(imageUri)
fun compressor(imageFilePath: File) {
val compressor = Compressor(this@AddNewStudentActivity)
Log.e("ImageFile Path","${imageFilePath}")
var compressedImage = compressor.setDestinationDirectoryPath(path.toString())
.setMaxWidth(120)
.setMaxHeight(150)
.setQuality(40)
.setCompressFormat(Bitmap.CompressFormat.JPEG)
.compressToFile(imageFilePath)
var compresseduri = Uri.fromFile(compressedImage)
mBinding.selectStudentsImageImageView.setImageURI(compresseduri)
}
fun compressor(imageFilePath: File) { val compressor = Compressor(this@AddNewStudentActivity) Log.e("ImageFile Path","${imageFilePath}") var compressedImage = compressor.setDestinationDirectoryPath(path.toString()) .setMaxWidth(120) .setMaxHeight(150) .setQuality(40) .setCompressFormat(Bitmap.CompressFormat.JPEG) .compressToFile(imageFilePath) var compresseduri = Uri.fromFile(compressedImage) mBinding.selectStudentsImageImageView.setImageURI(compresseduri)}
Did you find any solution for this issue ? Is this device specific issue ? On which device did you try this ?
I know this is a bit old, but just in case it helps anyone.
If you are trying to save to a file that does not have an extension, then it is affected by a bug in Util.kt:
val result = if (format == imageFile.compressFormat()) {
imageFile
} else {
File("${imageFile.absolutePath.substringBeforeLast(".")}.${format.extension()}")
}
This logic does not consider the potential of a file destination that has no extension, so instead of /data/my.app.id/cache/compressor - we get /data/my.imagename.extension - which doesn't work.
The destination must have a file extension. The extension does not need to be related to the image format at all, but there must be an extension.