Convert BufferedImage to Image in Java

Convert BufferedImage to Image in Java

In this post, we will see how to convert BufferImage to Image in java.

Convert BufferedImage to Image in Java

BufferedImage is an Image, so you don’t need to do any conversion.

You can just assign it as below:

Convert java.awt.image.BufferedImage to javafx.scene.image.Image in java

You can use SwingFXUtils.toFXImage() to convert image from java.awt.image.BufferedImage to javafx.scene.image.Image in java.

Convert Image to BufferedImage in Java

Since BufferedImage is an Image, you can do explicit casting to assign image to BufferedImage.

how To Scale BufferedImage in Java

There are multiple ways to scale BufferedImage in java.

Using BufferImage’s getScaledInstance()

You can use BufferImage's getScaledInstance() to scale BufferedImage in java.

Here is sample code:

Using imgscalr library

imgscalr provides resize() method to resize BufferedImage in java.
Add following dependency to pom.xml.

Here is sample code:

That’s all about Convert BufferedImage to Image in Java.

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *