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?

Alba Mendez
  • 4,432
  • 1
  • 39
  • 55
Lucky Man
  • 1,488
  • 3
  • 19
  • 41

1 Answers1

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);
Jon
  • 678
  • 1
  • 6
  • 9
  • 15
    This is an old question, but once should not forget to use ```dispose()``` after using drawImage(). – Crembo Jul 21 '14 at 09:14