简体   繁体   English

python pil颜色填充

[英]python pil colour fill

I have a shape below: 我的形状如下:

and I would like to colour only this shape, the background is transparent so I feel as if there is some way to colour an entire image. 而且我只想为这种形状着色,背景是透明的,所以我觉得好像有某种方法可以对整个图像着色。 Right now I am using put pixel and colouring every pixel in the picture but I am wondering if there is a more efficient way to do this? 现在,我正在使用放置像素并为图片中的每个像素着色,但是我想知道是否有更有效的方法?

putpixel(xy=(i,j), value=(red)) , where i,j is coloured if it exists putpixel(xy=(i,j), value=(red)) ,其中i,j如果存在则为彩色

Solution modified from: fill one colour 解决方案修改自: 填充一种颜色

Where these two lines were changed: 这两行更改的位置:

white_areas = (red == 138) & (blue == 138) & (green == 138) & (alpha == 255)
data[..., ][white_areas.T] = (25, 90, 0, 190)

previous solution: 先前的解决方案:

white_areas = (red == 255) & (blue == 255) & (green == 255)
data[..., :-1][white_areas.T] = (255, 0, 0) # Transpose back needed

Removed :-1 from data 已从数据中移除:-1

What these changes mean: also able to change opacity level 这些更改的含义:还可以更改不透明度级别

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM