Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
设置像素的RGB级别(Python、Jython) 对于pic中的每个像素: r=随机() 如果r_Python_Jython - Fatal编程技术网

设置像素的RGB级别(Python、Jython) 对于pic中的每个像素: r=随机() 如果r

设置像素的RGB级别(Python、Jython) 对于pic中的每个像素: r=随机() 如果r,python,jython,Python,Jython,其余的看不见的代码是正确的,我只是不知道如何将此函数表达得足够好,使其能够工作。我不知道您的其他代码,但它可能是这样的: For each pixel in pic: r= random() if r < 0.25: set the red level to randrange(0,256), set the green level to randrange(0,256) set the blue level to

其余的看不见的代码是正确的,我只是不知道如何将此函数表达得足够好,使其能够工作。

我不知道您的其他代码,但它可能是这样的:

   For each pixel in pic:
    r= random()      
    if r < 0.25:       
    set the red level to randrange(0,256), 
    set the green level to randrange(0,256) 
    set the blue level to randrange(0,256)
随机导入
对于pic.get_pixels()中的像素:#替换为获取像素的适当方式
如果random.random()<0.25:
pixel.red=random.randint(256)
pixel.green=random.randint(256)
pixel.blue=random.randint(256)

同样,我不知道如何获得像素列表,或者如何为每个像素设置RGB值,但结果是这样的。

我不知道您的代码的其他部分,但它是这样的:

   For each pixel in pic:
    r= random()      
    if r < 0.25:       
    set the red level to randrange(0,256), 
    set the green level to randrange(0,256) 
    set the blue level to randrange(0,256)
随机导入
对于pic.get_pixels()中的像素:#替换为获取像素的适当方式
如果random.random()<0.25:
pixel.red=random.randint(256)
pixel.green=random.randint(256)
pixel.blue=random.randint(256)
同样,我不知道如何获得像素列表,或者如何为每个像素设置RGB值,但结果是这样的。

您使用PIL吗

如果是这样的话,一个选择就是这样做

import random

for pixel in pic.get_pixels(): # Replace with appropiate way of getting the pixels
    if random.random() < 0.25:
        pixel.red = random.randint(256)
        pixel.green = random.randint(256)
        pixel.blue = random.randint(256)
哦。。。我看你明白了。好吧,不管怎样我都会把这个贴出来。

你在用PIL吗

如果是这样的话,一个选择就是这样做

import random

for pixel in pic.get_pixels(): # Replace with appropiate way of getting the pixels
    if random.random() < 0.25:
        pixel.red = random.randint(256)
        pixel.green = random.randint(256)
        pixel.blue = random.randint(256)

哦。。。我看你明白了。好吧,不管怎样,我都会发布这个。

像素的格式是什么??您可以从正确缩进开始。混合使用制表符和空格不是一个好主意……对于getPixels(pic)中的px,您应该将答案作为一个问题发布,并将其标记为可接受的答案pixel的格式是什么?您可以从正确缩进开始。混合使用制表符和空格并不是一个好主意……对于px-in-getPixels(pic),你应该将你的答案作为一个问题发布,并将其标记为已接受的答案