我正在尝试将一张图片“切”成两半并水平翻转两侧。请参见下面的链接。
原始图片:
输出需要是什么:
def mirrorHorizontal(picture):
mirrorPoint = getHeight(picture)/2
height = getHeight(picture)
for x in range(0, getWidth(picture)):
for y in range(0, mirrorPoint):
topPixel = getPixel(picture, x, y)
bottomPixel = getPixel(picture, x, height - y - 1)
color = getColor(topPixel)
setColor(bottomPixel, color)
那么我该如何水平翻转每一面,使其看起来像第二张图片呢?
getPixel
、setColor
和其他方法的是什么?) - jsbuenotop
和bottom
。在一次迭代中,你将修改top
,将其分配给bottom
。然后,当你到达bottom
时,你尝试将其设置为top
的颜色,只是现在top
是bottom
。因此,你的图片将有一半未被修改。避免这种情况的简单方法是创建一个具有相同尺寸的不同图像,并将原始图像映射到该图像上。 - NullUserException