AffineTransform on image / Byte[] to BufferedImage
Hi all,
I have an image set in a JPanel and I want to be able to perform Affine Transforms on it, preferably without having to extend JComponent and re-write paintComponent().
AFAIK, I can't do Affine Transformations directly on Images or ImageIcons, so I need to use a BufferedImage. I'd then do
Graphics2D g2d = myBufferedImage.createGraphics()
and use drawImage() to apply my transformations.
Question 1: Does this seem right? Do I need a BufferedImage? Is this the best way to do this?
Question 2: I need to crete a BufferedImage from a byte array.
Currently, I get my Image from a byte array like so:
byte[] imageBytes = image.getImageBytes();
try{
icon =new ImageIcon(imageBytes);
if (icon.getImageLoadStatus() != MediaTracker.COMPLETE){
thrownew Exception();
}
Image image = icon.getImage()//if I need access to the image itself
...
From there I could get a BufferedImage byBufferedImage bimage =
new BufferedImage(
image.getWidth(null),
image.getHeight(null),
BufferedImage.TYPE_INT_ARGB);
Graphics g = bimage.getGraphics();
g.drawImage(image, 0, 0,null);
However, this seems very round about. Is there a direct way to go from a byte[] to a BufferedImage?
Thanks for any advice!
Sam

