Jython:减少一半图像的颜色
Jython: reducing color in half an image
我试图减少下半部分图像中的红色,但我很困惑,这是我想出的代码,只是想知道是否有人可以指出为什么它对我不起作用?
def decreaseRed(pict):
width=getWidth(pict)
height=getHeight(pict)
canvas=makeEmptyPicture(width,height)
for x in range(0, width):
for y in range(0, height/2):
pixel = getPixel(pict,x,y)
newRed = getRed(pixel)*0.5
newGreen = getGreen(pixel)
newBlue = getBlue(pixel)
newColor = makeColor(newRed,newGreen,newBlue)
pixelCanvas = getPixel(canvas,x,y)
setColor(pixelCanvas,newColor)
show(pict)
show(canvas)
file=getMediaPath("testa.jpg")
pict=makePicture(file)
decreaseRed(pict)
我相信我找到了答案,这会将图像下半部分的红色减少到原始颜色的 70%。
def decreaseRed(pict):
width=getWidth(pict)
height=getHeight(pict)
canvas=makeEmptyPicture(width,height)
for x in range(0, width):
for y in range(0, height):
pixel = getPixel(pict,x,y)
newRed = getRed(pixel)
newGreen = getGreen(pixel)
newBlue = getBlue(pixel)
newColor = makeColor(newRed,newGreen,newBlue)
pixelCanvas = getPixel(canvas,x,y)
setColor(pixelCanvas,newColor)
for y in range(height/2,height):
pixel = getPixel(pict,x,y)
newRed = getRed(pixel)*0.7
newGreen = getGreen(pixel)
newBlue = getBlue(pixel)
newColor = makeColor(newRed,newGreen,newBlue)
pixelCanvas = getPixel(canvas,x,y)
setColor(pixelCanvas,newColor)
return canvas
file=getMediaPath("test.jpg")
pict=makePicture(file)
show(decreaseRed(pict))
我试图减少下半部分图像中的红色,但我很困惑,这是我想出的代码,只是想知道是否有人可以指出为什么它对我不起作用?
def decreaseRed(pict):
width=getWidth(pict)
height=getHeight(pict)
canvas=makeEmptyPicture(width,height)
for x in range(0, width):
for y in range(0, height/2):
pixel = getPixel(pict,x,y)
newRed = getRed(pixel)*0.5
newGreen = getGreen(pixel)
newBlue = getBlue(pixel)
newColor = makeColor(newRed,newGreen,newBlue)
pixelCanvas = getPixel(canvas,x,y)
setColor(pixelCanvas,newColor)
show(pict)
show(canvas)
file=getMediaPath("testa.jpg")
pict=makePicture(file)
decreaseRed(pict)
我相信我找到了答案,这会将图像下半部分的红色减少到原始颜色的 70%。
def decreaseRed(pict):
width=getWidth(pict)
height=getHeight(pict)
canvas=makeEmptyPicture(width,height)
for x in range(0, width):
for y in range(0, height):
pixel = getPixel(pict,x,y)
newRed = getRed(pixel)
newGreen = getGreen(pixel)
newBlue = getBlue(pixel)
newColor = makeColor(newRed,newGreen,newBlue)
pixelCanvas = getPixel(canvas,x,y)
setColor(pixelCanvas,newColor)
for y in range(height/2,height):
pixel = getPixel(pict,x,y)
newRed = getRed(pixel)*0.7
newGreen = getGreen(pixel)
newBlue = getBlue(pixel)
newColor = makeColor(newRed,newGreen,newBlue)
pixelCanvas = getPixel(canvas,x,y)
setColor(pixelCanvas,newColor)
return canvas
file=getMediaPath("test.jpg")
pict=makePicture(file)
show(decreaseRed(pict))