I just need to send file that is only less than 2 mb. I use file and bitmap. Used easyimage library in the project.
How to compare the regular imagefile.length() returns in kb when i divide by 1024. But bitmap image returns byte bitmap.bytecount
how to get values in kb of bitmap file? It loops until its totally compressed to 0 quality.
Code: var quality = 90
var imgKiloByteLength = imageFile.length() / 1024
var imgMegaByteLength = imgKiloByteLength / 1024 //returns in mb
if (imgKiloByteLength > 2048) {
while (imgKiloByteLength > 2048) { //reducing the quality until it comes under 2mb
var compressedBitmap = compressBitmap(bitmap, quality)
bitmap = compressedBitmap
Log.e("result",bitmap.getByteCount().toString())
Glide.with(this@EditProfileActivity).load(bitmap).into(profileImage)
Log.e("result", "image more than 2mb ${imgKiloByteLength}")
quality -= 10
}
} else {
Glide.with(this@EditProfileActivity).load(bitmap).into(profileImage)
Log.e("result", "image size ok ${imgKiloByteLength}")
}
What are things that i can do? Thanks in advance.