所以,刚刚发布了关于尝试完成我的comp sci项目的内容。我基本上完成了我需要做的所有事情但是,我试图让这个图像旋转90度,但是当我打开输出的图像时,它全是黑色的。我不确定它有什么问题。
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import java.awt.*;
public class Project6b
{
public static void main (String args[]) throws Exception
{
rotate90ToLeft("Jack.jpg","Jack2.jpg");
}
public static void rotate90ToLeft(String originalImage, String convertedImage) throws Exception
{
BufferedImage bufferImg = ImageIO.read(new File(originalImage));
BufferedImage bufferImgOut = new BufferedImage(bufferImg.getWidth(),bufferImg.getHeight(), bufferImg.getType());
for( int x = 0; x < bufferImg.getWidth(); x++ )
{
for( int y = 0; y < bufferImg.getHeight(); y++ )
{
int px = bufferImg.getRGB(x, y);
int destY = bufferImg.getWidth() - x - 1;
bufferImgOut.setRGB(y,destY, px);
}
}
File outputfile = new File(convertedImage);
ImageIO.write(bufferImgOut, "png", outputfile);
}
}
好的,我发现图像必须小于400x400。有什么方法可以让它适用于任何尺寸的图像吗?