zetbaitsu / Compressor

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

How to work with Bitmap #170

Open anandshivam44 opened 3 years ago

anandshivam44 commented 3 years ago

I am working with java and kotlin I have the image as Bitmap How can I pass image to Compressor.compress(context,filepath) It accepts only File type

jokomanza commented 1 year ago

I think the only way for now is to save the bitmap to a file first, then that file will be passed to the compressor

jokomanza commented 1 year ago

For example


withContext(Dispatchers.IO) {

    val tempImageFile = File(context.cacheDir, System.currentTimeMillis().toString());
    saveBitmap(image, tempImageFile)

    val compressedImageFile = Compressor.compress(context, tempImageFile)
}