简体   繁体   中英

How to fix error - TypeError: unsupported operand type(s) for -: 'tuple' and 'int'

I am opening a png file and then filling colour in that png file. My code is working for some png files but not for all.

from PIL import Image, ImageDraw

image = Image.open("H:/baibhav/MPEG7dataset/apple_1.png")
width, height = image.size
center = (int(0.5 * width), int(0.5 * height))
yellow = (255, 255, 0, 255)
ImageDraw.floodfill(image, xy=center, value=yellow)
image.show()

I am expecting a figure as an output but it gives following error:

TypeError: unsupported operand type(s) for -: 'tuple' and 'int'

simply change

image = Image.open("H:/baibhav/MPEG7dataset/apple_1.png")

to

image = Image.open("H:/baibhav/MPEG7dataset/apple_1.png").convert("RGBA")

To know more, please check this . A in RGBA is the alpha parameter. We use the alpha parameter when we want the color to get transparent. In simple words, it controls the opacity in an image.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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