0

enter image description here

The Logo i.e Circle is png image and its quality decreases like shown. Before posting this question, I referred to all the possible solutions from Stackoverflow but none of them work for me.

To resize the size of pictures according to my usage I'm currently using the method down below.

fun BITMAP_RESIZER(bitmap: Bitmap, newWidth: Int, newHeight: Int): Bitmap? {
    val scaledBitmap = Bitmap.createBitmap(newWidth, newHeight, Bitmap.Config.ARGB_8888)
    val ratioX = newWidth / bitmap.width.toFloat()
    val ratioY = newHeight / bitmap.height.toFloat()
    val middleX = newWidth / 2.0f
    val middleY = newHeight / 2.0f
    val scaleMatrix = Matrix()
    scaleMatrix.setScale(ratioX, ratioY, middleX, middleY)
    val canvas = Canvas(scaledBitmap)
    canvas.setMatrix(scaleMatrix)
    canvas.drawBitmap(
        bitmap,
        middleX - bitmap.width / 2,
        middleY - bitmap.height / 2,
        Paint(Paint.FILTER_BITMAP_FLAG)
    )
    return scaledBitmap
}

And as a result, you can see its quality still not improved. Apart from this solution, I have used all other methods but none works for me.

Can you let me know what is the exact thing I'm doing wrong or any other possible answer?

Prateek
  • 502
  • 5
  • 16
  • What is the quality of the original image? You could switch to an .svg image instead. – Sujit Mar 17 '21 at 05:16
  • I tried the SVG image but it doesn't affect it. The actual size of the image is 1000x370 and I need the size of 50 x 20. It's a .png type. – Prateek Mar 17 '21 at 05:19
  • Then it's because the image is too big. – Sujit Mar 17 '21 at 05:49
  • I tried with a small size image as well. – Prateek Mar 17 '21 at 05:52
  • Does this answer your question? [Bad image quality after resizing/scaling bitmap](https://stackoverflow.com/questions/4821488/bad-image-quality-after-resizing-scaling-bitmap) – emandt Mar 17 '21 at 10:14
  • Hey, @emandt I tried that answer after that I asked. – Prateek Mar 17 '21 at 11:50
  • i can't understand you correctly and your problem is occurring because you want output image of size `50*20`, i mean it's to low(may be).. – Vivek Thummar Mar 26 '21 at 12:02
  • Hey, @VivekThummar I have an image of the size 1000x300 but it will be too big. Right? And in my pdf file, I need a logo and the size I required is 50x20. Even if I go for 200x80 still image gets pixelated. Thanks – Prateek Mar 28 '21 at 03:05
  • I don't know if this will gonna work or not but you should try this - https://stackoverflow.com/a/66811781/10752962 – Vivek Thummar Mar 29 '21 at 06:08
  • I think you have to create new logo with lower size, so you can set it directly without resize or compress, i think it's better solution.. – Vivek Thummar Mar 29 '21 at 06:25
  • Hey, @VivekThummar I have created a new logo even with my size requirement but that doesn't help. https://github.com/prateekcode/TestReport I have shared the repo. I tried all possible ways before putting my query here. – Prateek Mar 30 '21 at 03:11
  • It seems that my knowledge has just been finished – Vivek Thummar Mar 30 '21 at 04:59

0 Answers0