我在翻转图像时遇到问题。我的程序应该显示默认图像和翻转图像。我想如果我可以用原始图片的 (width-1,height-1) 替换翻转图片的 (0,0) 像素,它会起作用,但是我得到的是这个,而不是得到原始图像。
这是我的代码:
import java.awt.Color;
public class Horizontal {
public static void main(String[] args)
{
Picture source = new Picture(args[0]);//name of picture.
Picture flip = new Picture(source.width(), source.height());//sets the width and height of source
for (int i =0; i < source.width(); i++)
{
int w = 1;
int sw = source.width()-w;
for (int j = 0; j < source.width(); j++)
{
int h=1;
int sh = source.height()-h;
Color SourceColor = source.get(sw,sh);// return the the color pixel of (sw,sh)
flip.set(i, j, SourceColor);//suppose to replace the (i,j) pixel of flip with source's (sw,sh) pixel
h++;
}
w++;
}
source.show();// shows the original image
flip.show(); // shows flipped version of image
}
}