Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
199 views
in Technique[技术] by (71.8m points)

java - Converting a BufferedImage to another type

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...