我需要将图像翻转到假想的水平线上,但不知道该怎么做。
这是我当前的代码,Eclipse 告诉我,hold 的值没有被使用,但我不明白为什么没有。感谢所有帮助。
public static void flipH(Picture p){
int height= p.getHeight();
int width= p.getWidth();
Pixel empty= new Pixel(v, 0, 0);
Pixel hold= new Pixel(v, 0, 0);
for(int i=0; i< height; i++) {
for(int j=0, r=width-1; j<width/2 && r>width/2; j++, r--) {
empty= p.getPixel(i, j);
hold = p.getPixel(i, r);
hold= empty;
}
}
}
最佳答案
empty和hold只是引用,又名指针,指向真实对象的箭头。 分配空并保持指向某个像素永远不会改变该像素。 要交换两个像素,您需要类似...
int a = p.getColorOfPixel(x, y1);
int b = p.getColorOfPixel(x, y2);
p.setColorOfPixel(x, y1, b);
p.setColorOfPixel(x, y2, a);
关于java - 在假想的水平线上翻转像素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43429673/