Getting list of pixel values from PIL

前端 未结 9 1183
感动是毒
感动是毒 2020-11-27 15:07

Guys, I\'m looking for a bit of assistance. I\'m a newbie programmer and one of the problems I\'m having at the minute is trying to convert a black & white .jpg

9条回答
  •  误落风尘
    2020-11-27 16:03

    Looks like PILlow may have changed tostring() to tobytes(). When trying to extract RGBA pixels to get them into an OpenGL texture, the following worked for me (within the glTexImage2D call which I omit for brevity).

    from PIL import Image
    img = Image.open("mandrill.png").rotate(180).transpose(Image.FLIP_LEFT_RIGHT)
    
    # use img.convert("RGBA").tobytes() as texels
    

提交回复
热议问题