bitmap — autopy module for working with bitmaps¶
This module defines the class Bitmap
for accessing bitmaps and searching
for bitmaps onscreen.
It also defines functions for taking screenshots of the screen.
Bitmap Object Methods¶

class
autopy.bitmap.
Bitmap
¶ 
save
(path: str, format: str=None)¶ Saves image to absolute path in the given format. The image type is determined from the filename if possible, unless format is given. If the file already exists, it will be overwritten. Currently only jpeg and png files are supported.
 Exceptions:
IOError
is thrown if the file could not be saved.ValueError
is thrown if image couldn’t be parsed.

copy_to_pasteboard
()¶ Copies image to pasteboard. Currently only supported on macOS.
 Exceptions:
IOError
is thrown if the image could not be copied.ValueError
is thrown if the image was too large or small.

point_in_bounds
(x: float, y: float) → bool¶ Returns
True
if the given point is contained inbmp.bounds
.

rect_in_bounds
(rect: Tuple[Tuple[float, float], Tuple[float, float]]) → bool¶ Returns
True
if the given rect is contained inbmp.bounds
.

open
(path: str) → Bitmap¶ Open the image located at the path specified. The image’s format is determined from the path’s file extension.

get_color
(x: float, y: float) → Tuple[int, int, int]¶ Returns
(r, g, b)
tuple describing the color at a given point. Exceptions:
ValueError
is thrown if the point out of bounds.

find_color
(color: Tuple[int, int, int], tolerance: float=None, rect: Tuple[Tuple[float, float], Tuple[float, float]]=None, start_point: Tuple[float, float]=None) → Tuple[float, float]¶ Attempts to find
color
insiderect
inbmp
from the givenstart_point
. Returns coordinates if found, orNone
if not. Ifrect
isNone
,bmp.bounds
is used instead. Ifstart_point
isNone
, the origin ofrect
is used.Tolerance is defined as a float in the range from 0 to 1, where 0 is an exact match and 1 matches anything.

find_every_color
(color: Tuple[int, int, int], tolerance: float=None, rect: Tuple[Tuple[float, float], Tuple[float, float]]=None, start_point: Tuple[float, float]=None) → List[Tuple[float, float]]¶ Returns list of all
(x, y)
coordinates insiderect
inbmp
matchingcolor
from the givenstart_point
. Ifrect
isNone
,bmp.bounds
is used instead. Ifstart_point
isNone
, the origin ofrect
is used.

count_of_color
(color: Tuple[int, int, int], tolerance: float=None, rect: Tuple[Tuple[float, float], Tuple[float, float]]=None, start_point: Tuple[float, float]=None) → int¶ Returns count of color in bitmap. Functionally equivalent to:
len(find_every_color(color, tolerance, rect, start_point))

find_bitmap
(needle: Bitmap, tolerance: float=None, rect: Tuple[Tuple[float, float], Tuple[float, float]]=None, start_point: Tuple[float, float]=None) → Tuple[float, float]¶ Attempts to find
needle
insiderect
inbmp
from the givenstart_point
. Returns coordinates if found, orNone
if not. Ifrect
isNone
,bmp.bounds
is used instead. Ifstart_point
isNone
, the origin ofrect
is used.Tolerance is defined as a float in the range from 0 to 1, where 0 is an exact match and 1 matches anything.

find_every_bitmap
(needle: Bitmap, tolerance: float=None, rect: Tuple[Tuple[float, float], Tuple[float, float]]=None, start_point: Tuple[float, float]=None) → [Tuple[float, float]]¶ Returns list of all
(x, y)
coordinates insiderect
inbmp
matchingneedle
from the givenstart_point
. Ifrect
isNone
,bmp.bounds
is used instead. Ifstart_point
isNone
, the origin ofrect
is used.

count_of_bitmap
(needle: Bitmap, tolerance: float=None, rect: Tuple[Tuple[float, float], Tuple[float, float]]=None, start_point: Tuple[float, float]=None) → int¶ Returns count of occurrences of
needle
inbmp
. Functionally equivalent to:len(find_every_bitmap(color, tolerance, rect, start_point))

cropped
(rect: Tuple[Tuple[float, float], Tuple[float, float]]) → Bitmap¶ Returns new bitmap object created from a portion of another.
 Exceptions:
ValueError
is thrown if the portion was out of bounds.

is_bitmap_equal
(bitmap: Bitmap, tolerance: float=None) → bool¶ Returns true if bitmap is equal to receiver with the given tolerance.

Functions¶
autopy.bitmap.
capture_screen
(rect: Tuple[Tuple[float, float], Tuple[float, float]]) → autopy.bitmap.Bitmap¶Returns a screengrab of the given portion of the main display, or the entire display if rect is
None
.
 Exceptions:
ValueError
is thrown if the rect is out of bounds.IOError
is thrown if the image failed to parse.