The following example demonstrates how to create a bitmap:
import MaxPlus # Bitmap Types class BitmapTypes(object): BMM_NO_TYPE = 0 # Not allocated yet BMM_LINE_ART = 1 # 1-bit monochrome image BMM_PALETTED = 2 # 8-bit paletted image. Each pixel value is an index into the color table. BMM_GRAY_8 = 3 # 8-bit grayscale bitmap. BMM_GRAY_16 = 4 # 16-bit grayscale bitmap. BMM_TRUE_16 = 5 # 16-bit true color image. BMM_TRUE_32 = 6 # 32-bit color: 8 bits each for Red, Green, Blue, and Alpha. BMM_TRUE_64 = 7 # 64-bit color: 16 bits each for Red, Green, Blue, and Alpha. BMM_TRUE_24 = 8 # 24-bit color: 8 bits each for Red, Green, and Blue. Cannot be written to. BMM_TRUE_48 = 9 # 48-bit color: 16 bits each for Red, Green, and Blue. Cannot be written to. BMM_YUV_422 = 10 # This is the YUV format - CCIR 601. Cannot be written to. BMM_BMP_4 = 11 # Windows BMP 16-bit color bitmap. Cannot be written to. BMM_PAD_24 = 12 # Padded 24-bit (in a 32 bit register). Cannot be written to. BMM_LOGLUV_32 = 13 BMM_LOGLUV_24 = 14 BMM_LOGLUV_24A = 15 BMM_REALPIX_32 = 16 # The 'Real Pixel' format. BMM_FLOAT_RGBA_32 = 17 # 32-bit floating-point per component (non-compressed), RGB with or without alpha BMM_FLOAT_GRAY_32 = 18 # 32-bit floating-point (non-compressed), monochrome/grayscale BMM_FLOAT_RGB_32 = 19 BMM_FLOAT_A_32 = 20 def CreateABitmap(): # This is one way to create a bitmap foo = MaxPlus.Factory.CreateBitmap() print 'Bitmap:', foo # First allocate some storage. This is where the type of bitmap is determined. # (see class BitmapTypes above) storage = MaxPlus.Factory.CreateStorage(BitmapTypes.BMM_TRUE_32) print 'BitmapStorage:', storage # Now we can get the bitmap info info = storage.GetBitmapInfo() print 'Bitmap Information:', info # Set some common properties on the bitmap info.SetWidth(720) info.SetHeight(620) info.SetName('My demonstration bitmap') info.SetGamma(2.2) # Verify a few things assert(storage.GetWidth() == 720) assert(storage.GetHeight() == 620) print info.GetName() # Allocate storage for writing to the bitmap storage.Allocate(info, 2) for x in range(720): for y in range(620): storage.PutPixel(x,y,(MaxPlus.Color64(64000-(x*(64000/720)),(y*(64000/720)),64000,64000))) foo.SetStorage(storage) foo.Display() CreateABitmap()
To create a bitmap, call Factory.CreateBitmap().
foo = MaxPlus.Factory.CreateBitmap()
You must also allocate storage for the bitmap by calling Factory.CreateStorage(). This method takes an integer as input; therefore, the class BitmapTypes was created to define available bitmap types and their corresponding integer values that can be passed to Factory.CreateStorage(). An object of class BitmapStorage is created.
storage = MaxPlus.Factory.CreateStorage(BitmapTypes.BMM_TRUE_32)
BitmapStorage.GetBitmapInfo() returns an object of class BitmapInfo and you can then call the BitmapInfo.SetWidth(), BitmapInfo.SetHeight(), BitmapInfo.SetName() methods and so forth to set properties on the bitmap.
info = storage.GetBitmapInfo() info.SetWidth(720) info.SetHeight(620) info.SetName('My demonstration bitmap') info.SetGamma(2.2)
Call BitmapStorage.Allocate() to allocate storage for writing to the bitmap.
storage.Allocate(info, 2)
To write the pixels, call BitmapStorage.PutPixel():
for x in range(720): for y in range(620): storage.PutPixel(x,y,(MaxPlus.Color64(64000-(x*(64000/720)),(y*(64000/720)),64000,64000)))
Finally, call Bitmap.SetStorage() and pass the BitmapStorage you created above as an argument.
foo.SetStorage(storage)
To display your bitmap, call Bitmap.Display().
Note: Factory.CreateBitmap() creates a bitmap instance that is never deleted, and therefore will always leak memory.