Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.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
Python 是什么导致动态创建的gif中出现瑕疵?_Python_Python Imaging Library_Gif_Image Manipulation_Artifact - Fatal编程技术网

Python 是什么导致动态创建的gif中出现瑕疵?

Python 是什么导致动态创建的gif中出现瑕疵?,python,python-imaging-library,gif,image-manipulation,artifact,Python,Python Imaging Library,Gif,Image Manipulation,Artifact,我使用PIL动态创建了一个GIF,我在Charizard的翅膀顶端得到了这个工件 下面是我用来创建gif的代码,我认为在gif上粘贴一个新的背景不会导致这个问题,但看起来这没有任何作用 images = [] length = min(pokemonImage1.n_frames, pokemonImage2.n_frames) for frameIndex in range(0, length): pokemonImage

我使用PIL动态创建了一个GIF,我在Charizard的翅膀顶端得到了这个工件 下面是我用来创建gif的代码,我认为在gif上粘贴一个新的背景不会导致这个问题,但看起来这没有任何作用

        images = []
        length = min(pokemonImage1.n_frames, pokemonImage2.n_frames)
        for frameIndex in range(0, length):
            pokemonImage1.seek(frameIndex)
            pokemonImage2.seek(frameIndex)
            pkmn1 = pokemonImage1.convert("RGBA")
            pkmn2 = pokemonImage2.convert("RGBA")
            imageInMemory = BytesIO()
            new_img = Image.new('RGBA', (800,400), (0, 0, 0, 0))
            new_img.paste(background, (0,0))
            new_img.paste(pkmn1, (600, 100), mask=pkmn1)
            new_img.paste(pkmn2, (100, 300), mask=pkmn2)
            new_img.save(imageInMemory, 'png')
            imageInMemory.name = "gifInMemory_" + str(frameIndex) + ".png"
            images.append(Image.open(imageInMemory))
            
        gifInMemory = BytesIO()
        images[0].save(gifInMemory, "gif", save_all=True, append_images=images[1:], loop=0, optimize=True, duration=20)
        gifInMemory.name = "battle.gif"
        gifInMemory.seek(0)

您是否尝试过使用
Image.save()
disposition
参数?此参数影响前一帧相对于背景的布置方式。尝试添加
disposition=2
,看看这是否有帮助。我刚试过,但不幸的是那似乎没什么用。我认为问题发生在for循环中,因为循环中的图像具有足够的伪影。当我向gif添加边界框时,它不再具有伪影。如果将边界框的alpha设置为0,则会重新显示瑕疵。您是否尝试过使用
Image.save()
disposition
参数?此参数影响前一帧相对于背景的布置方式。尝试添加
disposition=2
,看看这是否有帮助。我刚试过,但不幸的是那似乎没什么用。我认为问题发生在for循环中,因为循环中的图像具有足够的伪影。当我向gif添加边界框时,它不再具有伪影。如果将边界框的alpha设置为0,则会重新显示瑕疵。