Repository navigation
Expand file tree
/
Copy pathbitmap_fill_color.py
More file actions
72 lines (52 loc) · 2.16 KB
/
Copy pathbitmap_fill_color.py
File metadata and controls
72 lines (52 loc) · 2.16 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""Adds an overlay color to a Picture.
Topics:
* c4d.bitmaps.BaseBitmap
* c4d.bitmaps.GeClipMap
* GeClipMap.FillRect()
* GeClipMap.SetDrawMode()
"""
__author__ = "Maxime Adam"
__copyright__ = "Copyright (C) 2026 MAXON Computer GmbH"
__license__ = "Apache-2.0 License"
__version__ = "R18"
import c4d
def FillBitmapWithColor(srcBmp, rgba):
if not isinstance(srcBmp, c4d.bitmaps.BaseBitmap):
raise TypeError("Expected a BaseBitmap")
if not isinstance(rgba, c4d.Vector4d):
raise TypeError("Expected a Vector4d")
# Creates GeClipMap to do some drawing operation
geClipMap = c4d.bitmaps.GeClipMap()
if geClipMap is None:
raise RuntimeError("Failed to create a GeClipMap")
# Initializes the GeClipMap with our Bitmap
if not geClipMap.InitWithBitmap(srcBmp, None):
raise RuntimeError("Failed to initialize GeClipMap")
# Retrieves the weight and height of our picture
w, h = geClipMap.GetDim()
# Start the drawing
geClipMap.BeginDraw()
# Defines the raw mode to blend (means we do not override existing pixel and use opacity)
geClipMap.SetDrawMode(c4d.GE_CM_DRAWMODE_BLEND, c4d.GE_CM_SRC_MAX_OPACITY)
# Defines the colors used to paint a rectangle
geClipMap.SetColor(int(rgba.x), int(rgba.y), int(rgba.z), int(rgba.w))
# Paints a rectangle into all the pictures
geClipMap.FillRect(0, 0, w, h)
# End the drawing
geClipMap.EndDraw()
return geClipMap
def main():
# Opens a Dialog to choose a picture file
bitmapPath = c4d.storage.LoadDialog(type=c4d.FILESELECTTYPE_IMAGES, title="Please Choose an Image:")
if not bitmapPath:
return
# Loads the picture as a BaseBitmap
bmp = c4d.bitmaps.BaseBitmap()
if bmp.InitWith(bitmapPath)[0] != c4d.IMAGERESULT_OK:
raise RuntimeError("Failed to load the Picture")
# Retrieves a GeClipMap multiplied with a color. Value are from 0 to 255 for red, blue, green, alpha
geClip = FillBitmapWithColor(bmp, c4d.Vector4d(100.0, 0.0, 0, 100.0))
# Displays the Bitmap stored in the GeClipMap into the Picture Viewer
c4d.bitmaps.ShowBitmap(geClip.GetBitmap())
if __name__ == "__main__":
main()