Utrata jakości przy użyciu ImageIO.write

Zauważyłem znaczną utratę jakości przy użyciu ImageIO.write, w jaki sposób mogę wyłączyć automatyczną kompresję?

val baos: ByteArrayOutputStream = new ByteArrayOutputStream
val newBi = new BufferedImage(img.getWidth, img.getHeight, BufferedImage.TYPE_INT_RGB)
val gr = newBi.createGraphics()
gr.drawImage(img, 0, 0, img.getWidth(), img.getHeight(), Color.WHITE, null)
ImageIO.write(newBi, "jpeg", baos)
val b = baos.toByteArray
baos.close()

questionAnswers(4)

yourAnswerToTheQuestion