rotate an image and save it -> black image

hello,

I have to load an image from filesystem, rotate it, and save it on filesystem. I don't need to write it on the sceen...

This is my code... but all what i get is a new black image

[code//BufferedImage toStore

BufferedImage toStore = new BufferedImage(Width,Height,BufferedImage.TYPE_INT_RGB );

//creating the AffineTransform instance

AffineTransform affineTransform = new AffineTransform();

//rotate the image

affineTransform.rotate(Math.toRadians(90));

Graphics2D g2d =toStore.createGraphics();

//draw the image using the AffineTransform

g2d.drawImage(img, affineTransform, null);

//write the image to filesystem

ImageIO.write(toStore,"BMP",new File(pathname));[/code]

Message was edited by:

aneuryzma

[811 byte] By [aneuryzmaa] at [2007-11-27 6:00:52]
# 1

import java.awt.Graphics2D;

import java.awt.geom.AffineTransform;

import java.awt.image.BufferedImage;

import java.io.*;

import javax.imageio.ImageIO;

public class LoadAndSave {

public static void main(String[] args) throws IOException {

String path = "images/cougar.jpg";

BufferedImage image = ImageIO.read(new File(path));

int w = image.getWidth();

int h = image.getHeight();

BufferedImage toStore = new BufferedImage(h, w, image.getType());

Graphics2D g2 = toStore.createGraphics();

double x = (h - w)/2.0;

double y = (w - h)/2.0;

AffineTransform at = AffineTransform.getTranslateInstance(x, y);

at.rotate(Math.toRadians(90), w/2.0, h/2.0);

g2.drawRenderedImage(image, at);

g2.dispose();

ImageIO.write(toStore, "BMP", new File("loadAndSave.bmp"));

}

}

crwooda at 2007-7-12 16:39:42 > top of Java-index,Security,Cryptography...