python - 是什么导致动态创建的 gif 中的伪影?
问题描述
我正在使用 PIL 动态创建一个 GIF,我在 Charizard 的翅膀尖端得到了这个神器 https://imgur.com/a/GD9wUwR 下面是我用来创建 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)
解决方案
推荐阅读
- asp.net-mvc - 如何在 ASP.NET MVC 5 中对 WebApi 的自定义身份验证过滤器使用 Ninject 依赖注入?
- html - Angular12获取API使表格数据不显示
- api - 亚马逊广告 API 引发 HTTP 401 Unauthorized
- ios - 当颤动桌面应用程序没有聚焦或最小化时检测按下的键
- c++ - cmake find_package 指定路径 redux
- javascript - 在对象中搜索用户,如果找到则返回键名
- sql - 使表中的两列唯一
- c# - 如果对象为空,我如何不序列化对象
- python - 如何使用 pytest 测试使用烧瓶创建的路由?
- python - 扁平化 cdl 网表