22

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?

2
  • @user172825 Welcome to StackOverflow! I recommend you to change your username. Commented Nov 19, 2011 at 13:10
  • 1
    This is very helpful! +1 Commented Jun 4, 2016 at 2:12

1 Answer 1

39

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);
Sign up to request clarification or add additional context in comments.

2 Comments

This is an old question, but once should not forget to use dispose() after using drawImage().
I know this is a common method, but it is also super slow. Is there anything faster?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.