【发布时间】:2015-12-01 15:23:22
【问题描述】:
所以我必须使用 java.awt.color 来翻转一些导入的图像。
这是我实现在垂直轴上翻转图像的主要方法:
public void execute (Pixmap target)
{
Dimension bounds = target.getSize();
// TODO: mirror target image along vertical middle line by swapping
// each color on right with one on left
for (int x = 0; x < bounds.width; x++) {
for (int y = 0; y < bounds.height; y++) {
// new x position
int newX = bounds.width - x - 1;
// flip along vertical
Color mirrorVert = target.getColor(newX, y);
target.setColor(x, y, new Color (mirrorVert.getRed(),
mirrorVert.getGreen(),
mirrorVert.getBlue()));
}
}
}
但是,当它执行时,而不是图像,翻转,我得到的是这样的:
感谢大家的帮助
【问题讨论】:
-
好吧,你没有删除以前的颜色
-
“通过将右侧的每种颜色与左侧的一种颜色交换来沿垂直中线镜像目标图像”-您基本上错过了“交换”部分
-
您正在就地替换颜色,因此当您从左侧读取像素时,它们已经被覆盖。这就像“交换 x = 4 和 y = 2”,然后您执行
y = x; x = y。你最终会得到两个值 4 (y = 4, x = y = 4)。 -
@MuratK。那么我该如何去除以前的颜色呢?
-
@zubergu 我怎么会错过交换部分?我以为当我设置 NewX 坐标时,我在交换