zetbaitsu / Compressor

An android image compression library.
7.04k stars 961 forks source link

Save the file to the new path #183

Open float85 opened 3 years ago

float85 commented 3 years ago

Hello i want to change the link to save the default file to my folder, where can i change it. thank

old: /data/user/0/com.example.camerademo001/cache/ new: file:///storage/emulated/0/DCIM/

source code:

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if (requestCode == CAMERA_REQUEST) { actualImage = FileUtilCompressor.from(this, tempFilePath)?.also { // actualImageView.setImageBitmap(loadBitmap(it)) // actualSizeTextView.text = String.format("Size : %s", getReadableFileSize(it.length())) // clearImage() }

        compressImage()

    }
}
private fun compressImage() {
    actualImage?.let {
        lifecycleScope.launch {
            // Default compression
            compressedImage = Compressor.compress(this@CameraUp, File(tempFilePath)){
                resolution(1280, 720)
                quality(80)
                format(Bitmap.CompressFormat.JPEG)
                size(597_152) // 2 MB
            }
            setCompressedImage()
        }
    } ?: showError("Please choose an image!")
}
vijayredjinni commented 2 years ago

var file = Compressor.compress(applicationContext,actualImage)

compress file but file path is change, so retrofit server side image not uploaded.

old path : /storage/emulated/0/Download/pexels-matheus-bertelli-573299.jpg new path : /data/user/0/com.example.redjinni/cache/compressor/pexels-matheus-bertelli-573299.jpg

Pleases suggest.