Reputation: 542
I have one image file of size 2mb named file.jpg and i want to decrease its size before sending it to server but i don't want the image to get distorted. There are similar threads but most of them are converting the file into zip format which i don't want to do.
So please help me out.
Upvotes: 0
Views: 574
Reputation: 19223
read your JPG as bitmap and use
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, out);`
quality in range 95-100 won't harm your quality (you already use JPG in fact), but will significantly reduce size
some docs in HERE
edit: this question is a duplicate...
Upvotes: 0
Reputation: 682
Use https://github.com/zetbaitsu/Compressor library:
it will give almost lossless compression result.
val compressedImageFile = Compressor.compress(context, actualImageFile) {
default()
destination(myFile)
}
after compression you can delete your actual image and use new destination image file path.
Upvotes: 1