逐渐使照片褪色 [英] Fading a picture gradually
问题描述
此功能的想法是仅淡化图片的上半部分(使其逐渐变暗).这是我所拥有的,但似乎使所有上半部分变成黑色.
The idea of this function is to fade the top half only of the picture (make it gradually darker). Here is what I have but it seems to be making all of the top half solid black.
def fadeDownFromBlack(pic1):
w=getWidth(pic1)
h=getHeight(pic1)
for y in range(0,h/2):
for x in range(0,w):
px=getPixel(pic1,x,y)
setBlue(px,y*(2.0/h))
setRed(px,y*(2.0/h))
setGreen(px,y*(2.0/h))
推荐答案
让我们在这里只看一行:
Let's look at just one line here:
setBlue(px,y*(2.0/h))
这里关键部分是
y*(2.0/h)
y随您的变化而变化.让我们尝试一些简单的y和h值.假设h为100,我们将检查y何时同时为0和50(h/2).对于y = 0,我们得到0.对于y = 50,我们得到1.如果您的颜色值范围是256,其中0是最暗的,那也就不足为奇了.您所拥有的值范围是从0.到1.,但是我想您想要的是将该数字乘以旧颜色值乘以该值.
y changes, as you go down. Let's try some simple values for y and h. Let's say h is 100 and we will examine when y is both 0 and 50 (h/2). For y = 0, we get 0. For y = 50, we get 1. If your range of values for the colors is 256 with 0 being the darkest, then no wonder this is black. What you have is a range of values from 0. to 1., but I'm guessing what you want is to take that number and times it by the old color value.
您想要的是:
setBlue(px,y*(2.0/h)*getBlue(px))
以及其他颜色的类似东西.
and similar things for the other colors.
这篇关于逐渐使照片褪色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!