pythonware.com ::: library ::: Python Imaging Library Handbook (2003 Edition)

Back   Next

On this page:
The Dib Class
Methods

The ImageWin Module

The ImageWin module contains support to create and display images on Windows. It can be used with PythonWin as well as other user interface toolkits that provides access to Windows device contexts.

The Dib Class

Dib

ImageWin.Dib(image) => Dib instance

ImageWin.Dib(mode, size) => Dib instance

This constructor creates a Windows bitmap from a PIL image, or from a given mode and size.

The mode can be one of "1", "L", or "RGB".

If the display requires a palette, this constructor creates a suitable palette and associates it with the image. For an "L" image, 128 greylevels are allocated. For an "RGB" image, a 6x6x6 colour cube is used, together with 20 greylevels.

To make sure that palettes work properly under Windows, you must call the palette method upon certain events from Windows. See the method descriptions below.

Methods

expose

dib.expose(hdc)

Expose (draw) the image using the given device context handle. The handle is an integer representing a Windows HDC handle.

In PythonWin, you can use the GetHandleAttrib method of the CDC class to get a suitable handle.

draw

dib.draw(hdc, destination)

dib.draw(hdc, destination, source)

Same as expose, but allows you to specify where to draw the image, and what part of it to draw.

The destination and source areas are given as 4-tuple rectangles. If the source is omitted, the entire image is copied. If the source and the destination have different sizes, the image is resized as necessary.

palette

dib.palette(handle)

Installs the palette associated with the image in the given device context. The handle argument is an integer representing a Windows HDC handle.

This method should be called upon QUERYNEWPALETTE and PALETTECHANGED events from Windows. If this method returns a non-zero value, one or more display palette entries were changed since the last updated, and the image should be redrawn.

paste

dib.paste(image, bbox)

Paste an image into the bitmap image. The bbox argument is a 4-tuple defining the left, upper, right, and lower pixel coordinate. If None is used instead of a tuple, the entire image is copied. In all cases, the size of the pasted image must match the size of the region. If the image mode does not match the bitmap mode, conversions are automatically applied.

Back   Next