原文:https://blog.csdn.net/robinzhou/article/details/6960345
当需要将一张有透明部分的图片粘贴到一张底片上时,如果用Python处理,可能会用到PIL,但是PIL中 有说明,在粘贴RGBA模式的图片是,alpha通道不会被帖上,也就是不会有透明的效果,当然也给出了解决方法,就是粘贴的时候,将RGBA的的alpha通道提取出来做为mask传入。
im.paste(image, box, mask)
Same as above, but updates only the regions indicated by the mask. You can use either "1", "L" or "RGBA" images (in the latter case, the alpha band is used as mask). Where the mask is 255, the given image is copied as is. Where the mask is 0, the current value is preserved. Interm
本文介绍了如何使用Python的PIL库和OpenCV库处理RGBA格式的透明图片粘贴。在PIL中,通过提取RGBA图片的alpha通道作为mask实现透明效果;在OpenCV中,通过读取图片并进行灰度处理、阈值设置和反色操作,实现透明图片的粘贴。示例代码展示了具体的操作步骤。
订阅专栏 解锁全文
3822

被折叠的 条评论
为什么被折叠?



