Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileNotFound Exception When i try to .compressToFile(imageUri) #188

Open
HassanAhamd opened this issue Aug 9, 2021 · 2 comments
Open

FileNotFound Exception When i try to .compressToFile(imageUri) #188

HassanAhamd opened this issue Aug 9, 2021 · 2 comments

Comments

@HassanAhamd
Copy link

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)

}

@pradeep-orbi
Copy link

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 ?

@mikedawson
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants