bitmap — autopy module for working with bitmaps

This module defines the class Bitmap for accessing bitmaps and searching for bitmaps on-screen.

It also defines functions for taking screenshots of the screen.

Bitmap Object Methods

bmp.find_bitmap(needle, tolerance=0.0, rect=None)

Searches for needle in bmp. Returns tuple (x, y) of position if found, or None if not.

bmp.count_of_bitmap(needle, tolerance=0.0, rect=None)

Returns count of occurrences of needle in haystack. Functionally equivalent to:

len(bmp.find_every_bitmap(needle, tolerance))
bmp.find_every_bitmap(needle, tolerance=0.0, rect=None)

Returns list of all (x, y) coordinates where needle occurs in bmp.

bmp.point_in_bounds(x, y)

Returns True if x < bmp.width and y < bmp.height, or False if not.

bitmap.Bitmap.open(filepath, format)

Opens image at absolute filepath in the given format. The image type is determined from the filename if possible, unless format is given.

Exceptions:
  • IOError is thrown if the image could not be opened.
bmp.to_string()

Returns compressed, printable string representing bitmap, to be used with Bitmap.from_string().

Exceptions:
  • IOError is thrown if the string could not be created.
bmp.find_every_color(color, tolerance=0.0, rect=None)

Returns list of all coordinates inside rect in bmp matching color. If rect is None, the entire image is searched.

bmp.get_color(x, y)

Returns hexadecimal value describing the RGB color at the given point.

Exceptions:
  • ValueError is thrown if the point out of bounds.
bmp.get_portion(origin, size)

Returns new bitmap object created from a portion of another.

Exceptions:
  • ValueError is thrown if the portion was out of bounds. IOError is thrown if the portion could not be copied.
bitmap.Bitmap.from_string(string)

Creates bitmap from string created by bmp.to_string().

Exceptions:
  • ValueError is thrown if the given string was invalid.
bmp.copy_to_pboard()

Copies image to pasteboard. Currently only supported on Windows and Mac OS X.

Exceptions:
  • OSError is thrown if the image could not be copied.
bmp.find_color(color, tolerance=0.0, rect=None)

Attempts to find color inside rect in bmp; returns coordinates if found, or None if not. If rect is None, the entire image is searched.

bmp.count_of_color(color, tolerance=0.0, rect=None)

Returns count of color in bitmap. Functionally equivalent to:

len(find_every_color(color, tolerance, rect))
bmp.save(filepath, [format])

Saves image to absolute filepath in the given format. The image type is determined from the filename if possible, unless format is given. Note that if the file already exists, it WILL be overwritten. Check yourself first if you do not desire this.

Exceptions:
  • IOError is thrown if the image could not be saved.

Functions

bitmap.capture_screen(rect=None)

Returns a screengrab of the given portion of the main display, or the entire display if rect is None.

Exceptions:
  • OSError is thrown if the screengrab was unsuccessful.
  • ValueError is thrown if the rect is out of bounds.