使用python处理RGBA格式的透明图片的粘贴
2011-11-11 16:28
633 查看
当需要将一张有透明部分的图片粘贴到一张底片上时,如果用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. Intermediate values can be used for transparency effects.
Note that if you paste an "RGBA" image, the alpha band is ignored. You can work around this by using the same image as both source image and mask.
代码如下:
#读取底片
imp = Image.open('20111110_170002.jpg')
#读取要粘贴的图片 RGBA模式
imq = Image.open('attachment.png')
#分离通道
r,g,b,a = imq.split()
#粘贴
imp.paste(imq,(100, 100, 171, 172),mask = a)
显示:
imp.show()
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. Intermediate values can be used for transparency effects.
Note that if you paste an "RGBA" image, the alpha band is ignored. You can work around this by using the same image as both source image and mask.
代码如下:
#读取底片
imp = Image.open('20111110_170002.jpg')
#读取要粘贴的图片 RGBA模式
imq = Image.open('attachment.png')
#分离通道
r,g,b,a = imq.split()
#粘贴
imp.paste(imq,(100, 100, 171, 172),mask = a)
显示:
imp.show()
相关文章推荐
- wince下IImage接口的使用,处理jpeg、bmp、png等格式图片
- 在IE6中使用透明格式的PNG图片
- 使用python生成excel格式的图片
- 使用Python的urllib2模块处理url和图片的技巧两则
- Python图片处理库Wand的简单使用
- 使用Python获取并处理IP的类型及格式
- 使用Python的urllib2模块处理url和图片的技巧两则
- 使用python进行图像处理-调整图片大小
- 使用Python PIL模块处理图片
- 使用CDC进行颜色/图片合成(透明处理)
- 原生C#使用mask处理图片透明代码
- 自己封装的一个Java版图片工具,具备压缩,伸缩变换,透明处理,格式转换等功能.
- Python宝典第八、九章:Python多媒体编程及使用PIL处理图片
- python处理图片之PIL模块简单使用方法
- 使用python进行图像处理-调整图片大小
- 使用ThinkPHP上传类处理KindEditor上传的图片(主要是注意返回格式的方式)
- 使用python处理没有被Web用到的图片
- python︱处理与使用json格式的数据(json/UltraJSON/Demjson)
- VC++使用CImage PNG转BMP图片透明背景处理
- 使用java程序对图片宽高及格式进行重置(包括透明背景的图片)