c4d.bitmaps.BaseBitmap
¶
The bitmap class can be used to load, read, draw and save bitmap pictures of various formats. Be sure to call
BaseBitmap.Init()
before you attempt to use a newly allocated bitmap.
Note
Bitmaps are organized so that x = y = 0 is the top left corner.
Note
Though the bitmap class can work with other bit depths than 24 and 32, please note that only these function support other bit depths:
BaseBitmap.GetBw()
,
BaseBitmap.GetBh()
,
BaseBitmap.GetBt()
,
BaseBitmap.GetBpz()
,
BaseBitmap.Init()
,
BaseBitmap.GetPixelCnt()
,
BaseBitmap.SetPixelCnt()
,
BaseBitmap.SetCMAP()
,
BaseBitmap.AddChannel()
,
BaseBitmap.RemoveChannel()
,
BaseBitmap.GetAlphaPixel()
,
BaseBitmap.SetAlphaPixel()
,
BaseBitmap.GetChannelCount()
,
BaseBitmap.GetChannelNum()
(to use higher bit depths or multiple channels, see
MultipassBitmap
).
See also
Copy32BitImage.py for an example showing how to copy the internal data of an image to a new one.
c4d.bitmaps.
BaseBitmap
¶
BaseBitmap.SetPixel()
BaseBitmap.GetPixel()
BaseBitmap.SetAlphaPixel()
BaseBitmap.GetAlphaPixel()
BaseBitmap.GetPixelCnt()
BaseBitmap.SetPixelCnt()
BaseBitmap.Within()
BaseBitmap.GetSize()
BaseBitmap.GetBw()
BaseBitmap.GetBh()
BaseBitmap.GetBt()
BaseBitmap.GetBpz()
BaseBitmap.GetColorMode()
BaseBitmap.AddChannel()
BaseBitmap.RemoveChannel()
BaseBitmap.GetChannelNum()
BaseBitmap.GetChannelCount()
BaseBitmap.IsMultipassBitmap()
BaseBitmap.SetData()
BaseBitmap.GetData()
BaseBitmap.GetDirty()
BaseBitmap.SetDirty()
- c4d.bitmaps.BaseBitmap
BaseBitmap.
__init__
(
)
¶
Return type: |
BaseBitmap
|
---|---|
Returns: | The new bitmap. |
BaseBitmap.
__getitem__
(
key
)
¶
This is similar to
GetPixel()
. An example:
r, g, b = bmp[5, 5] #returns the color of a pixel at position x(5), y(5)
Raises: |
IndexError
– If the pixel position is out of the bitmap boundaries. See
GetSize()
,
GetBw()
and
GetBh()
.
|
---|---|
Parameters: | key ( int ) – The pixel position. |
Return type: | tuple(int, int, int) |
Returns: | The color of a pixel. Range between 0-255 . |
BaseBitmap.
__setitem__
(
key
,
value
)
¶
This is similar to
GetPixel()
. An example:
bmp[5, 5] = (50, 255, 50) #returns the color of a pixel at position x(5), y(5)
Note
The
Vector
objects does not support item deletion. For instance by calling
del(bmp[5,5])
.
Raises: |
IndexError
– If the pixel position is out of the bitmap boundaries. See
|
---|---|
Parameters: |
|
BaseBitmap.
__eq__
(
self
,
other
)
¶
BaseBitmap.
__ne__
(
self
,
other
)
¶
Check if two references point to the same bitmap.
Note
Does not compare if two references are equal.
BaseBitmap.
SetPixel
(
x
,
y
,
r
,
g
,
b
)
¶
Sets the pixel at
(x, y)
to the color specified by
(r,g,b) (0 <= r/g/b <= 255)
. Similar to the
__setitem__()
.
Note
Currently this method does no range check of x and y . This might be added in the future. Please do the check on your own.
Parameters: |
|
---|---|
Return type: |
bool |
Returns: |
True if successful, otherwise False . |
BaseBitmap.
GetPixel
(
x
,
y
)
¶
Retrieves the color at (
x,y
). Similar to the
__getitem__()
.
Note
Currently this method does no range check of x and y . This might be added in the future. Please do the check on your own.
Parameters: |
|
---|---|
Return type: |
list of int |
Returns: |
The color of the pixel. Range between 0-255 . |
BaseBitmap.
GetPixelCnt
(
x
,
y
,
cnt
,
buffer
,
inc
,
dstmode
,
flags
[
,
conversion=None
]
)
¶
Reads cnt pixels from ( x , y ) in the bitmap to the buffer with mode dstmode , incrementing inc bytes for each pixel.
Parameters: |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Return type: |
bool |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Returns: |
True if successful, otherwise False . |
BaseBitmap.
SetPixelCnt
(
x
,
y
,
cnt
,
buffer
,
inc
,
srcmode
,
flags
)
¶
Sets cnt pixels at ( x , y ) in the bitmap from buffer with mode srcmode , incrementing inc bytes for each pixel. The following example shows you how to read/write from/into an image:
""" Test Example: BaseBitmap.SetPixelCnt()/BaseBitmap.GetPixelCnt() This example shows how to copy the internal data of a 32 bit per-channel image to a new one. """ import c4d from c4d import bitmaps, gui, storage def main(): path = storage.LoadDialog(type=c4d.FILESELECTTYPE_IMAGES, title="Please Choose a 32 Bit Image:") if not path: return # Create and initialize selected image orig = bitmaps.BaseBitmap() if orig.InitWith(path)[0] != c4d.IMAGERESULT_OK: gui.MessageDialog("Cannot load image \"" + path + "\".") return # Check if channel depth is really 32 bit if orig.GetBt()/3 != 32: gui.MessageDialog("The image \"" + path + "\" is not a 32 bit per-channel image.") return # Get selected image infos width, height = orig.GetSize() bits = orig.GetBt() # Create the copy and initialize it copy = bitmaps.BaseBitmap() copy.Init(width, height, bits) # Calculate the number of bytes per pixel inc = orig.GetBt()/8 # Each pixel has RGB bits, so we need an offset of 'inc' bytes per pixel # the image has 32 bits per-channel : (32*3)/8 = 12 bytes per pixel (1 byte = 8 bits) # the image has 3 channels per pixel (RGB) : 12/3 = 4 bytes per component = 1 float # Create a byte sequence buffer large enough to store the copied image pixels sq = storage.ByteSeq(None, width*height*inc) for row in xrange(height): offset = sq.GetOffset(row*(width*inc)) # Offset on bitmap row + offset bytes per pixel orig.GetPixelCnt(0, row, width, offset, inc, c4d.COLORMODE_RGBf, c4d.PIXELCNT_0) # Read pixels from the original bitmap to the buffer #Example: RGB value of first pixel (only for 32 bits) #import struct #r, g, b = struct.unpack("fff", sq[0:12]) #print r, g, b for row in xrange(height): offset = sq.GetOffset(row*(width*inc)) # Offset on bitmap row + offset bytes per pixel copy.SetPixelCnt(0, row, width, offset, inc, c4d.COLORMODE_RGBf, c4d.PIXELCNT_0) # Set pixels in bitmap copy bitmaps.ShowBitmap(orig) # Show original bitmaps.ShowBitmap(copy) # Show copied image if __name__=='__main__': main()
Parameters: |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Return type: |
bool |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Returns: |
True if successful, otherwise False . |
BaseBitmap.
GetInternalChannel
(
)
¶
Get the internal read-only alpha channel. The internal alpha channel is the one that’s saved together with the picture, with those formats that support this. If no internal alpha is available, None is returned.
Return type: | c4d.bitmaps.BaseBitmap |
---|---|
Returns: | The internal alpha channel. |
BaseBitmap.
GetAlphaPixel
(
channel
,
x
,
y
)
¶
Get the alpha value at ( x,y ).
Note
Currently this method does no range check of x and y . This might be added in the future. Please do the check on your own.
Parameters: |
|
---|---|
Return type: |
int |
Returns: |
The alpha value. Range is 0 to 255 . |
BaseBitmap.
SetAlphaPixel
(
channel
,
x
,
y
,
val
)
¶
Sets the alpha value at (x,y) to val . The valid range of val is 0 to 255 .
Note
Currently this method does no range check of x and y . This might be added in the future. Please do the check on your own.
Parameters: |
|
---|
BaseBitmap.
Init
(
x, y[, depth=24][, flags=INITBITMAPFLAGS_0]
)
¶
Note
The bitmap class only supports up to 4 channels. Also, most image loaders will only load one alpha channel.
Initializes the bitmap to the given dimensions and depth. Any previous data in the bitmap object is lost.
Parameters: |
|
||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Return type: |
int |
||||||||||||||||||
Returns: |
The result:
|
BaseBitmap.
InitWith
(
name
[
,
frame=-1
]
)
¶
Note
The bitmap class only supports up to 4 channels. Also, most image loaders will only load one alpha channel.
Loads a file into the bitmap. The file can be either a movie or a picture. The file format is automatically detected:
result, ismovie = bmp.InitWith(path) if result==c4d.IMAGERESULT_OK: #int check # picture loaded if ismovie==True: #bool check pass # file is a movie else: pass # file is no movie
Parameters: |
|
||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Return type: |
tuple(int, bool) |
||||||||||||||||||
Returns: |
The result for first element:
The second element is True if the loaded picture was a movie. |
BaseBitmap.
FlushAll
(
)
¶
Resets the bitmap to its initial state and frees allocated memory. Requires a call to
Init()
before the bitmap can be used again.
BaseBitmap.
SetColorProfile
(
profile
)
¶
Copy the color profile to the bitmap.
Parameters: | profile ( c4d.bitmaps.ColorProfile ) – The profile. |
---|---|
Return type: | bool |
Returns: | True on success, otherwise False . |
BaseBitmap.
GetColorProfile
(
)
¶
Get a new color profile instance of the bitmap.
Return type: | c4d.bitmaps.ColorProfile |
---|---|
Returns: | The profile. |
BaseBitmap.
CopyTo
(
dst
)
¶
Copies the image to dst .
Parameters: | dst ( c4d.bitmaps.BaseBitmap ) – The bitmap to copy the image to. |
---|---|
Return type: | bool |
Returns: | Success of copying the image. |
BaseBitmap.
CopyPartTo
(
dst
,
x
,
y
,
w
,
h
)
¶
Copies a part of the image to dst .
Parameters: |
|
---|---|
Return type: |
bool |
Returns: |
Success of copying the image. |
BaseBitmap.
GetClone
(
)
¶
Clones the Bitmap and returns a new instance.
Return type: | c4d.bitmaps.BaseBitmap |
---|---|
Returns: | The clone. |
BaseBitmap.
GetClonePart
(
x
,
y
,
w
,
h
)
¶
Clones a part of the bitmap, specified by the rectangle (x,y) to (x+w,y+h) .
Parameters: |
|
---|---|
Return type: | |
Returns: |
The cloned bitmap, or None if an error occured. |
BaseBitmap.
Save
(
name
,
format
[
,
data=None
,
savebits=SAVEBIT_0
]
)
¶
Saves the bitmap to a file. Valid formats are:
FILTER_TIF TIFF FILTER_TGA TGA FILTER_BMP BMP FILTER_IFF IFF FILTER_JPG JPEG FILTER_PICT Mac Pict FILTER_PSD Photoshop FILTER_RLA RLA FILTER_RPF RPF FILTER_B3D Bodypaint FILTER_TIF_B3D TIFF B3D FILTER_PSB Photoshop Big FILTER_AVI AVI Movie FILTER_MOVIE Quicktime Movie FILTER_QTVRSAVER_PANORAMA QTVR Panorama FILTER_QTVRSAVER_OBJECT QTVR Object FILTER_HDR HDR FILTER_EXR_LOAD EXR (Load) FILTER_EXR EXR FILTER_PNG PNG FILTER_IES IES FILTER_DPX DPX
Parameters: |
|
||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Return type: |
int |
||||||||||||||||||||||
Returns: |
True
if
|
BaseBitmap.
GetChannelCount
(
)
¶
Returns the number of alpha channels in the bitmap, including the internal channel.
Return type: | int |
---|---|
Returns: | Number of alpha channels. |
BaseBitmap.
Within
(
x
,
y
)
¶
Checks if a position is in the bitmap.
Parameters: |
|
---|---|
Return type: |
bool |
Returns: |
True if the coordinate is in the bitmap. |
BaseBitmap.
GetSize
(
)
¶
Returns the size of the bitmap in pixels. If the bitmap hasn’t been initialized the return values are 0. (This is the only way to see if a bitmap has been initialized.):
#bmp is a BaseBitmap instance x, y = bmp.GetSize()
Return type: | list of int |
---|---|
Returns: | Bitmap width and height in pixels, or 0 if the bitmap is not initialized. |
BaseBitmap.
GetBw
(
)
¶
Returns the width of the bitmap in pixels. If the bitmap hasn’t been initialized the return value is 0. (This is the only way to see if a bitmap has been initialized.)
Return type: | int |
---|---|
Returns: | Bitmap width in pixels, or 0 if the bitmap is not initialized. |
BaseBitmap.
GetBh
(
)
¶
Returns the height of the bitmap in pixels.
Return type: | int |
---|---|
Returns: | Bitmap height in pixels. |
BaseBitmap.
GetBt
(
)
¶
Returns the number of bits per pixel.
Return type: | int |
---|---|
Returns: | The number of bits. |
BaseBitmap.
SetCMAP
(
i
,
r
,
g
,
b
)
¶
If the image in the bitmap has 8 bit indexed color, this function can be used to set the palette entries. All four parameters must be between 0 and 255 .
Parameters: |
|
---|
BaseBitmap.
GetBpz
(
)
¶
Returns the number of bytes per line.
Return type: | int |
---|---|
Returns: | Number of bytes per line. |
BaseBitmap.
SetData
(
id
,
data
)
¶
Sets bitmap data.
Parameters: |
|
||||||
---|---|---|---|---|---|---|---|
Return type: |
bool |
||||||
Returns: |
True if the data could be set, otherwise False . |
BaseBitmap.
GetData
(
id
,
default
)
¶
Gets bitmap data.
Parameters: |
|
||||||
---|---|---|---|---|---|---|---|
Return type: |
float or type (default) |
||||||
Returns: |
the retrieved data, or default . |
BaseBitmap.
ScaleBicubic
(
dst
,
src_xmin
,
src_ymin
,
src_xmax
,
src_ymax
,
dst_xmin
,
dst_ymin
,
dst_xmax
,
dst_ymax
)
¶
Scales the bitmap rectangle ( src_xmin , src_ymin , src_xmax , src_ymax ) to fit in the destination bitmap rectangle ( dst_xmin , dst_ymin , dst_xmax , dst_ymax ) and copies it there. The scaling, if necessary, is done using bicubic interpolation. The destination needs to be initialized before calling this function:
bmp.ScaleBicubic(dst, 0, 0, bmp.GetBw()-1, bmp.GetBh()-1, 0, 0, dst.GetBw()-1, dst.GetBh()-1)
Note
This function can currently only scale down, i.e. the destination needs to be smaller or equal to the source in size.
Parameters: |
|
---|
BaseBitmap.
ScaleIt
(
dst
,
intens
,
sample
,
inprop
)
¶
Scales the bitmap to fit in the destination bitmap and copies it there. The destination needs to be initialized with the destination size before calling this function.
Parameters: |
|
---|
BaseBitmap.
AddChannel
(
internal
,
straight
)
¶
Adds a new alpha channel to the image.
Parameters: |
|
---|---|
Return type: |
int |
Returns: |
The new channel. |
BaseBitmap.
RemoveChannel
(
channel
)
¶
Removes the specified channel from the bitmap.
Parameters: | channel ( c4d.bitmaps.BaseBitmap ) – The alpha channels to use. |
---|
BaseBitmap.
GetChannelNum
(
num
)
¶
Returns the channel ID from the channel index.
Parameters: |
num
(
int
) – A number between 0 and
GetChannelCount()
.
|
---|---|
Return type: | c4d.bitmaps.BaseBitmap |
Returns: | The requested channel. |
BaseBitmap.
GetDirty
(
)
¶
Private.
Return type: | int |
---|---|
Returns: | Dirty count, incremented when the bitmap changes. |
BaseBitmap.
SetDirty
(
)
¶
Makes the bitmap dirty.
BaseBitmap.
IsMultipassBitmap
(
)
¶
Checks if the image is a
MultipassBitmap
.
Return type: | bool |
---|---|
Returns: |
True
if the image is a
MultipassBitmap
, otherwise
False
|
BaseBitmap.
GetColorMode
(
)
¶
Returns the color mode of the bitmap.
Return type: | int | ||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Returns: |
Color mode
|
BaseBitmap.
GetMemoryInfo
(
)
¶
Get the size of the memory used by the bitmap.
Return type: | long |
---|---|
Returns: | Memory size of the bitmap. |
BaseBitmap.
GetUpdateRegionBitmap
(
)
¶
Get the updated region of a bitmap.
Return type: | c4d.bitmaps.BaseBitmap |
---|---|
Returns: | The updated region. |