我想编写一个程序,使用 x 和 y 计数器变量从图像的右下角一直到左上角读取像素。该程序会将右下角的像素分配给左上角,并以这种方式分配每个像素,从而翻转图像。
到目前为止我的主要代码:
Scanner reader = new Scanner(System.in);
APImage image = new APImage("MrB.JPG");
image.draw();
int width = image.getWidth();
int height = image.getHeight();
APImage brandnew = new APImage(width, height);
int y = 0;
for(y < height; y--;)
{
int x = width - 1
for(x >= 0; x++;)
{
Pixel opixel = image.getPixel(x, y);
}
}
System.out.println("Press the return key to continue");
reader.nextLine();
brandnew.draw();
任何帮助将不胜感激,干杯。
最佳答案
这应该可以做到:
for(int x = 0; x < width; y++){
for(int y = 0; y < height; y++){
flipped.setPixel(width - 1 - x, height - 1 - y, original.getPixel(x,y));
}
}
关于java - 如何使用嵌套 for 循环翻转图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39710410/