我设法旋转图像,180 degrees但希望旋转它90 degrees clockwise可以有人编辑我的代码,以便它做到这一点解释.谢谢.
private void rotateClockwise()
{
if(currentImage != null){
int width = currentImage.getWidth();
int height = currentImage.getHeight();
OFImage newImage = new OFImage(width, height);
for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
newImage.setPixel( x, height-y-1, currentImage.getPixel(x, y));
}
}
currentImage = newImage;
imagePanel.setImage(currentImage);
frame.pack();
}
}
Run Code Online (Sandbox Code Playgroud) 我无法将图像向右旋转90度。我需要能够在Java中分别旋转图像。唯一的事情。不幸的是,我需要在特定点绘制图像,并且没有一种方法带有参数1.分别旋转图像和2.允许我设置x和y。任何帮助表示赞赏
public class Tumbler extends GraphicsProgram{
public void run() {
setSize(1000,1000);
GImage original = new GImage("sunset.jpg");
add(original, 10, 10);
int[][] pixels = original.getPixelArray();
int height = pixels.length;
int width = pixels[0].length;
// Your code starts here
int newheight = width;
int newwidth = height;
int[][] newpixels = new int[newheight][newwidth];
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
newpixels[j][height-1-i] = pixels[i][j];
}
}
GImage image = new GImage(newpixels);
add(image, …Run Code Online (Sandbox Code Playgroud) 我有一个缓冲图像,即:
BufferedImage buffer = ImageIO.read(new File(file));
Run Code Online (Sandbox Code Playgroud)
现在我想旋转它。.所以我该怎么做?
以前我使用过图像格式,即:
Image image = ImageIO.read(new File(file));
Run Code Online (Sandbox Code Playgroud)
并可以使用以下方法轻松旋转图像:
AffineTransform at = new AffineTransform();
at.rotate(0.5 * angle * Math.PI, width/2, height/2);
Run Code Online (Sandbox Code Playgroud)
但是我不赞成如何使用缓冲图像?你能帮助我吗??