Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting a BufferedImage to another type

Tags:

The most convenient method to read an image from a source (Files, InputStreams, URLs) is:

BufferedImage myImage = ImageIO.read( source ); 

But then, how to convert myImage to a BufferedImage.TYPE_USHORT_565_RGB format?

like image 828
Lucky Man Avatar asked Nov 19 '11 12:11

Lucky Man


People also ask

How do I change a buffered image to an image?

You can use BufferImage's getScaledInstance() to scale BufferedImage in java. final int SCALE = 2; Image img = new ImageIcon("MyFile. png").

What is the difference between BufferedImage and image?

List, the difference between Image and BufferedImage is the same as the difference between List and LinkedList. Image is a generic concept and BufferedImage is the concrete implementation of the generic concept; kind of like BMW is a make of a Car. Show activity on this post. Image is an abstract class.

How do I get bytes from BufferedImage?

This article shows how to convert a BufferedImage to a byte array or byte[] . BufferedImage bi = ImageIO. read(new File("c:\\image\\mypic. jpg")); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.

What is the use of BufferedImage?

Java For Testers Java BufferedImage class is a subclass of Image class. It is used to handle and manipulate the image data. A BufferedImage is made of ColorModel of image data. All BufferedImage objects have an upper left corner coordinate of (0, 0).


1 Answers

You can create a new BufferedImage of the required type and then draw the original image on it, something like:

    BufferedImage bufImg = ImageIO.read( imageURL );     BufferedImage convertedImg = new BufferedImage(bufImg.getWidth(), bufImg.getHeight(), BufferedImage.TYPE_USHORT_565_RGB);     convertedImg.getGraphics().drawImage(bufImg, 0, 0, null); 
like image 186
Jon Avatar answered Oct 22 '22 01:10

Jon