I am using putpixel method from PIL module. It seems that it expects that r,g,b values are integers. I am trying to draw a mandelbrot set and the formula I'm using to calculate color returns float type numbers. TypeError: integer argument expected, got float
If your values are already scaled to 0-255, try:
im.putpixel((x, y), tuple(int(c) for c in pixel))
If they're scaled 0-1, you just need to add a multiply:
im.putpixel((x, y), tuple(int(c*255.999 for c in pixel))
PS the preferred way of doing pixel level access is with the load
function:
pix = im.load()
pix[x, y] = tuple(...)
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.