[PIL] about the difference between pudata and putpixel

Tom B. sbabbitt at commspeed.net
Sun Aug 29 10:28:36 EDT 2004


"Hillairet Julien" <jh at nospam.com> wrote in message
news:pan.2004.08.29.10.54.40.204024 at nospam.com...
> Hello,
>
> I don't understand how "putdata" from the PIL works :
>
> I've got a (N,N) matrix : "color" (an array from numarray lib.), where
> (N,N) is the size of a image.
>
> The next code, give to each pixel of the image the color (an integer
> 0~255) which is associate in the "color" matrix (an integer matrix,
> 0~255). It works well, but it's a bit slow:
>
> for i in range(N):
>     for j in range(N):
>         im.putpixel((i,j), color[i][j])
>
> Although, this code doesn't work:
>
> im.putdata(color)
>
> There is no error message, but the image's pixels stay black (0) ! (The
> color matrix is not an 0-matrix !)
>
>
> Is someone can explain me my misunderstanding of putdata ?
>
>
> Thanks a lot,
>
> Julien Hillairet

Check your picture mode.

import Image
import random

pyimg = Image.new('RGB',(10,10))
ll = []
for i in range(100):

ll.append((random.randint(1,255),random.randint(1,255),random.randint(1,255)
)) # a tuple of RGB values
pyimg.putdata(ll)
pyimg.show() # drag open the pill view window to see (its not large enough)


Tom





More information about the Python-list mailing list