Main Index : Reference :

BaseBitmap


Description

A bitmap class.

Definition

class BaseBitmap
{
public:
  BaseBitmap([int] width, [int] height);
    
  [bool] Load([Filename] file, [[int] frame = 0]);
  [bool] Save([Filename] file, [[int] type = FILTER_TIF], [[BaseContainer] data]);
    
  [int] GetWidth();
  [int] GetHeigth();
  
  [vector] GetPixel([int] x, [int] y);

  [bool] SetPen([vector] col);
  [bool] DrawPixel([int] x, [int] y, [[vector] col]);
  [bool] DrawLine([int] x1, [int] y1, [int] x2, [int] y2);
  [bool] DrawRect([int] x1, [int] y1, [int] x2, [int] y2);	

  [bool] CopyTo([BaseBitmap] dest);
  [BaseBitmap] GetClone();
}

Explanation

The bitmap class can be used to load, read, draw and save bitmap pictures of various formats. New in V6 is the option to specify the export filter type and additional data (compressor settings) when saving.

Members

BaseBitmap( width, height )

BaseBitmap([int] width, [int] height);

Constructor. Creates a bitmap with the dimensions specified by width and height.


Load( file, [frame] )

[bool] Load([Filename] file, [[int] frame = 0]);

Loads the file specified by the filename file into the bitmap. If the file is a movie one can specify which frame to load. If no frame is specified, frame 0 is loaded. CINEMA 4D automatically detects the file format. Returns TRUE if successful.

Save( file, [type], [data] )

[bool] Save([Filename] file, [[int] type = FILTER_TIF], [[BaseContainer] data]);

Saves the bitmap to the file specified by the filename file. Returns TRUE if successful. Optionally one can specify the file format with the type option, using these enums:

Type Format
FILTER_TIF TIFF
FILTER_TGA TGA
FILTER_BMP Windows BMP
FILTER_IFF IFF
FILTER_JPG JPEG
FILTER_PICT Macintosh PICT
FILTER_PSD Photoshop

Some of the formats allow further control over compression settings and such. Include those options in the container data. The following ids are available:

Container ID Type Range Meaning
JPGSAVER_QUALITY [int] 0..100 JPEG Quality


GetWidth()

[int] GetWidth();

Returns the width of the bitmap.

GetHeigth()

[int] GetHeigth();

Returns the height of the bitmap.


GetPixel( x, y )

[vector] GetPixel([int] x, [int] y);

Returns the color in the bitmap at the position given by x and y. If not 0<=x<width and 0<=y<height, the function returns NIL.


SetPen( col )

[bool] SetPen([vector] col);

Sets the pen color to col. Returns TRUE if successful.

DrawPixel( x, y, [col] )

[bool] DrawPixel([int] x, [int] y, [[vector] col]);

Draws a pixel at the position given by x and y with the color col. If no color is specified the current pen color is used. If not 0<=x<width and 0<=y<height, the function returns FALSE. Otherwise it returns TRUE if successful.

DrawLine( x1, y1, x2, y2 )

[bool] DrawLine([int] x1, [int] y1, [int] x2, [int] y2);

Draws a line from the point (x1,y1) to the point (x2,y2) using the current pen color. Returns TRUE if successful.

DrawRect( x1, y1, x2, y2 )

[bool] DrawRect([int] x1, [int] y1, [int] x2, [int] y2);

Fills a rectangle area with the upper left corner at the point (x1,y1) and the lower right corner at the point (x2,y2) using the current pen color. Returns TRUE if successful.


CopyTo( dest )

[bool] CopyTo([BaseBitmap] dest);

Copies the bitmap to the bitmap dest. This overwrites dest and changes its dimensions to fit the copied bitmap. Returns TRUE if successful.

GetClone()

[BaseBitmap] GetClone();

Returns a copy of the bitmap object.

Example

// Loads a bitmap from the file MyFile
var bm = new(BaseBitmap, 1, 1);
bm->Load(MyFile);

// Creates a bitmap with a cross
var bm = new(BaseBitmap, 64, 64);

bm->SetPen(vector(0.0)); // Black
bm->DrawRect(0, 0, 63, 63);

bm->SetPen(vector(1.0, 0.0, 0.0)); // Red
bm->DrawLine(0, 0, 63, 63);
bm->DrawLine(63, 0, 0, 63);