identify x,y coordinates in an image

Cliff Wells logiplexsoftware at earthlink.net
Wed Nov 7 14:57:08 EST 2001


On Wednesday 07 November 2001 08:48, John Hunter wrote:

>     Cliff> PIL is an excellent choice and will allow you to zoom to
>     Cliff> particular point in an image.  wxPython is an alternative
>     Cliff> to Tkinter (there isn't any native support for wxPython
>     Cliff> from PIL, but a couple of simple routines will convert
>     Cliff> between PIL images and wxImages - I can provide them if you
>     Cliff> like).
>
> I would like these conversion routines; thanks.

Since I've been asked for them so often (three times and counting!), I'll 
post them to the list.  I believe I got the original code from Piddle... it's 
been a while, so I'm not too sure.  And yes, those are tab-indentations (damn 
you four-spacers!).

def PILToWX(image):
	"convert a PIL image to a wxImage"
	if (image.mode != 'RGB'):
		image = image.convert('RGB')
	imageData = image.tostring('raw', 'RGB')
	imageWx = wxEmptyImage(image.size[0], image.size[1])
	imageWx.SetData(imageData)
	return imageWx

def WXToPIL(image, mode = 'RGBA'):
	"convert a wxImage to a PIL RGBA image"
	imageData = image.GetData()
	size = (image.GetWidth(), image.GetHeight())
	imagePIL = Image.fromstring('RGB', size, imageData)
	if mode != 'RGB':
		imagePIL = imagePIL.convert(mode)
	return imagePIL


-- 
Cliff Wells
Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308
(800) 735-0555 x308




More information about the Python-list mailing list