透明像素在 PIL 中被粘贴为黑色 [英] Transparet pixels are being pasted as black in PIL

查看:48
本文介绍了透明像素在 PIL 中被粘贴为黑色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我粘贴了一个带有透明像素的图像,但在最终图像中它们是黑色的

I paste an image with transparent pixels, but they are black in the final image

img = Image.new('RGBA', (100, 100), "white")

arbol16 = Image.open("arbol16.png")

img.paste(arbol16,( 0, 0, 16, 16))

img.show()

arbol16.png 图像文件:

推荐答案

我认为您(可以理解)对 img.show() 显示的内容感到困惑——我认为这是错误的(实际上可能是一个错误).在我的 Windows 系统上,显示了一个临时的 .BMP 图像,看起来透明像素是黑色的.

I think you're (understandably) being confused by what the img.show() is displaying — which I believe is wrong (and may in fact be a bug). On my Windows system a temporary .BMP image is displayed, and it looks like the transparent pixels are black.

但是,如果您在末尾添加类似 img.save('arbol16_mod.png') 的行,然后通过在某些图像中手动打开来查看那个图像文件文件查看程序,如画图、Windows 照片查看器或 Photoshop,结果是正确的.

However if you add a line like img.save('arbol16_mod.png') at the end and then view that image file by manually opening it in some image file viewing program, such as Paint, Windows Photo Viewer, or Photoshop, the result is correct.

这篇关于透明像素在 PIL 中被粘贴为黑色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆