Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Image or ImageIcon to byte []  RSS feed

 
Michael Remijan
Author
Ranch Hand
Posts: 131
7
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, here is a weird question. I would like to know how I go from a java.awt.Image or a java.awt.ImageIcon back to a byte []? I am working on a project to resize images. I can read in the bytes and use the Image.getScaledInstance() instance to do the resizing but after that I can't see any way to get the bytes back out of Image or ImageIcon.

Any Suggestions?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't post the same question to multiple forums; I deleted the other copy you posted. See here for an explanation.

As to the answer: draw into a BufferedImage, then use the getRGB() method to grab some or all of the pixels. You can grab just a rectangular piece, or the whole thing.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!