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¶
-
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:
-
-
IOErroris thrown if the file could not be saved. -
ValueErroris thrown if image couldn’t be parsed.
-
-
copy_to_pasteboard()¶ -
Copies image to pasteboard. Currently only supported on macOS.
- Exceptions:
-
-
IOErroris thrown if the image could not be copied. -
ValueErroris thrown if the image was too large or small.
-
-
point_in_bounds(x: float, y: float) → bool¶ -
Returns
Trueif the given point is contained inbmp.bounds.
-
rect_in_bounds(rect: Tuple[Tuple[float, float], Tuple[float, float]]) → bool¶ -
Returns
Trueif the given rect of the form((x, y), (width, height))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 hexadecimal value describing the color at a given point.
- Exceptions:
-
-
ValueErroris 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
colorinsiderectof the form((x, y), (width, height))inbmpfrom the givenstart_point. Returns coordinates if found, orNoneif not. IfrectisNone,bmp.boundsis used instead. Ifstart_pointisNone, the origin ofrectis 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 insiderectinbmpmatchingcolorfrom the givenstart_point. IfrectisNone,bmp.boundsis used instead. Ifstart_pointisNone, the origin ofrectis 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
needleinsiderectinbmpfrom the givenstart_point. Returns coordinates if found, orNoneif not. IfrectisNone,bmp.boundsis used instead. Ifstart_pointisNone, the origin ofrectis 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 insiderectinbmpmatchingneedlefrom the givenstart_point. IfrectisNone,bmp.boundsis used instead. Ifstart_pointisNone, the origin ofrectis 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
needleinbmp. 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:
-
-
ValueErroris 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
rectisNone. Therectparameter is in the form of((x, y), (width, height)).
- Exceptions:
ValueErroris thrown if the rect is out of bounds.
IOErroris thrown if the image failed to parse.