我無法將圖像向右旋轉90度。 我需要能夠在java中分別旋轉圖像。唯一的事情。不幸的是,我需要在特定的點上繪製圖像,並且沒有任何方法可以使圖像單獨旋轉,並且允許我設置x和y。任何幫助理解在Java中向右旋轉90度圖像
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, width+20, 10);
// Your code ends here
}
[我相信這是你想要什麼] [1] [1]:http://stackoverflow.com/問題/ 4156518 /在Java中旋轉圖像 –