win32 display jpg file

Ilariu Raducan lale at fotonation.com
Wed Apr 30 06:49:14 EDT 2003


Thank you all for your quick replays.

I check the last outline and I can share my findings with you

in document  OnOpenDocument add:
	im = Image.open(filename)
         self.dib = ImageWin.Dib(im.mode,im.size)
         self.dib.paste(im)
	#make in redraw
	#self.frame.InvalidateRect()
	#or
	#self.UpdateAllViews()
in View
     def OnDraw(self,dc):
         self.dib.expose(dc.GetHandleAttrib())

Regards,
Lale


Fredrik Lundh wrote:
> Mark Hammond wrote:
> 
> 
>>>Does anybody knows how to display a JPG file in pythonwin and draw lines
>>>over it?
>>
>>With a fair bit of work :)  You would need to use PIL to decode the jpg
>>and convert it to a bitmap.  IIRC, Pythonwin still has a PIL demo in it.
> 
> 
> if you cannot find it, here's an outline:
> 
> when you load the image:
> 
>     from PIL import Image, ImageWin
> 
>     try:
>         im = Image.open(filename)
>     except IOError:
>         # deal with the error
>     else:
>         # check image size; resize if necessary
>         # check the image mode
>         if im.mode not in ("1", "L", "RGB"):
>             im = im.convert(Image.getmodebase(im.mode))
>         dib = ImageWin.Dib(im)
>         # store the "dib" variable somewhere
> 
> in the PAINT handler, just do:
> 
>     dib.expose(dc)
> 
> where "dc" is a device context for the window, cast to an integer.
> according to the PIL docs, "you can use the GetHandleAttrib method
> of the CDC class to get a suitable handle."
> 
> in 1.1.4, you can pass in ImageWin.HWND(wnd) instead of the dc,
> where wnd is a window handle cast to an integer.
> 
> in all versions, you can also use
> 
>     dib.draw(dc, (x0, y0, x1, y1))
> 
> where (x0, y0, x1, y1) is the coordinates for where you want the
> image to appear.
> 
> (expose is the same thing as draw(dc, (0, 0, width, height))
> 
> </F>
> 
> 
> 
> 





More information about the Python-list mailing list