Bitmap is lost the quality of image when getting from the storage of android

311 Views Asked by At

I am facing issue with Bitmap image quality when getting a image file from internal storage and show on imageView. How to show image file with original quality using bitmap.

Here is my code

 fun renderPdf(renderer: PdfRenderer, pagesBitmap: MutableList<Bitmap>, dir: File) {
    try {
        for (i in 0 until PAGE_COUNT) {
            val document: PDDocument = PDDocument.load(dir)
            val pdfRenderer = PDFRenderer(document)
            val bim = pdfRenderer.renderImage(i, 3.5f, Bitmap.Config.ARGB_8888!!)
            pagesBitmap.add(bim!!)
            document.close()
            // Save the render result to an image
            val path: String =
                Environment.getExternalStorageDirectory().toString() + "/.AOF/aof_$i.jpg"
            val renderFile = File(path)
            val fileOut = FileOutputStream(renderFile)
            pagesBitmap[i].compress(Bitmap.CompressFormat.JPEG, 100, fileOut)
            fileOut.close()
        }

        ivForm.pagesBitmap = pagesBitmapFiles
        ivForm.displayPDFDocument()
        renderer.close()
    } catch (e: IOException) {
        Log.e("PdfBox-Android-Sample", "Exception thrown while rendering file", e)
    } finally {
        callDocumentType()
    }
}
0

There are 0 best solutions below