forked from cool-RR/python_toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitmap_tools.py
More file actions
35 lines (26 loc) · 973 Bytes
/
bitmap_tools.py
File metadata and controls
35 lines (26 loc) · 973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Copyright 2009-2017 Ram Rachum.
# This program is distributed under the MIT license.
'''Defines bitmap-related tools.'''
import pkg_resources
import wx
def color_replaced_bitmap(bitmap, old_rgb, new_rgb):
'''Replace all appearances of `old_rgb` with `new_rgb` in `bitmap`.'''
old_r, old_g, old_b = old_rgb
new_r, new_g, new_b = new_rgb
image = wx.ImageFromBitmap(bitmap)
assert isinstance(image, wx.Image)
image.Replace(old_r, old_g, old_b, new_r, new_g, new_b)
return wx.BitmapFromImage(image)
def bitmap_from_pkg_resources(package_or_requirement, resource_name):
'''
Get a bitmap from a file using `pkg_resources`.
Example:
my_bitmap = bitmap_from_pkg_resources('whatever.images', 'image.jpg')
'''
return wx.Bitmap(
wx.Image(
pkg_resources.resource_stream(package_or_requirement,
resource_name),
wx.BITMAP_TYPE_ANY
)
)