Value> Bitmap Value |
The Bitmap class provides storage of and low-level access to 3ds Max bitmaps.
Bitmaps can be temporary objects that are resident only in memory, or they can be associated with a file on disk.
Those bitmaps associated with files have a non-null .fileName property and are either load-only or save-only, but not both (this is with respect to file I/O; all bitmaps in memory can have their pixels modified by the setPixel() functions).
You make load-only bitmaps with the openBitmap() and selectBitmap() functions.
You make temporary or save-only bitmaps with the bitmap() constructor, or with the render() , copy() , or getChannelAsMask() functions. To make them savable, they must have a valid file name, supplied either on the constructor with a fileName: parameter or by setting the .fileName property.
bitmap <width <height> [filename:<filename_string>] \ [numframes:<integer>] \ [color:<color>] \ [gamma:<float>] \ [pixelAspect:<float>] \ [channels:<channel_name array>]\ [hdr:<bool>]
Creates an empty bitmap. The bitmap value returned is a savable bitmap.
The filename: parameter allows you to set the name of the file the bitmap will be saved to using the save method. Specifying an existing bitmap file name does not load the contents of the bitmap file into the bitmap value.
The numframes: parameter allows you to create a multi-frame bitmap.
The color: parameter allows you to set the initial color of all pixels in the bitmap.
The gamma: parameter allows you to set the gamma for the newly created bitmap.
The pixelAspect: parameter allows you to set the pixel aspect for the newly created bitmap.
The channels: parameter lets you specify the channels to be created. It is also available as a property. For a list of valid names, see the getChannel method documentation.
When the optional hdr: parameter introduced in 3ds Max 8 is set to true, the constructor creates a 32 bit per channel bitmap value instead of an 8 bit per channel bitmap value.
Returns a bitmap value containing the contents of the specified bitmap file. The bitmap value returned is a load-only bitmap.
If the specified bitmap file does not exist, a runtime error was generated in 3ds Max 9 and earlier.
If the specified bitmap does not exist, a value of undefined is returned in 3ds Max 2008and higher.
This method displays a Image Input selection browser for the user to select a bitmap file. Returns a bitmap value containing the contents of the selected bitmap file, or the value undefined if the user presses Cancel in the browser. The bitmap value returned is a load-only bitmap.
Copies an existing bitmap, creating an unique instance of the bitmap.
If the source bitmap is load-only, the bitmap value returned is a temporary bitmap value, with a null filename and just one frame.
If the source is a multi-frame file, it snaps the current frame into the new copy, which becomes frame 0.
Lets you get or set the file name associated with the bitmap.
Yields an array of 256 colors (a bug in the current 3ds Max SDK prevents working with paletted files of other than 256 entries). Take care accessing this array with colors indexes retrieved by the getIndexedPixels() function described below, because these indexes are 0-based and MAXScript array indexes are 1-based. Yields undefined if the bitmap is not paletted. Currently you cannot create a paletted bitmap in MAXScript, however you can read and write to a pre-existing paletted bitmap.
Get and set the current frame number in a multi-frame file. Setting this property is permitted only on load-only bitmaps. The frame number is 0-based for inherently multi-frame files, such as .avi and .mov.
The number of frames in a multi-frame file, yields 1 for a single image file.
Returns bitmap's height in pixels.
Returns bitmap's width in pixels.
Get and set the gamma value of the bitmap.
<bitmap>.inputGamma : {#auto | #default | Float}
Returns the input gamma mode of the bitmap.
This value reflects the Gamma mode that was set when a bitmap value was loaded from an image file.
See Bitmap Gamma and MAXScript for details.
Available in 3ds Max 2014 and higher.
<bitmap>.inputGammaValue : Float
Returns the actual input gamma value of the bitmap.
See Bitmap Gamma and MAXScript for details.
Available in 3ds Max 2014 and higher.
Returns the bitmap's pixel aspect. Note that this is the aspect of the pixel, not the aspect of the bitmap image.
This property lets you get and set the bitmap channels available in the bitmap. For a list of valid names, see the getChannel method documentation.
This property contains true if the bitmap has an alpha channel and false if it does not.
Opens a virtual frame buffer (VFB) displaying the image.
Changes to the bitmap are not automatically displayed to the VFB.
To update the VFB, you need to call this function again.
Setting the frame property of the bitmap value does cause the VFB to update.
Each bitmap has its own VFB, i.e., if you display two different bitmaps, two VFBs will be displayed.
NEW in 3ds Max 2015: If the optional keyword argument caption: is specified as string, it will be displayed as the caption in the title bar of the VFB.
Close the VFB associated with the bitmap if open.
Saves the current state of the bitmap. Make sure the file name has been set first.
When saving multi-frame image files, the effect of the frame: keyword parameter is different depending on the type of output file.
Inherently multi-frame files, such as .avi and .mov, ignore the frame: parameter and always write to the next output file frame in sequence on each save() ; you cannot randomly write frames or rewrite frames already saved.
Saving image sequences (such as .bmp, jpg, .tga) requires supplying the frame: parameter and causes the frame number to be appended to the output file name for each frame saved. This effectively generates a sequence of image files suitable for building an IFL.
The output file remains open until you call close on the bitmap.
The save() function can only be called on a savable bitmap. You will get a runtime error if you attempt to save a bitmap opened with openBitmap() or selectBitmap() .
The gamma: keyword parameter can be used in 3ds Max 2014 and higher to set the Gamma mode or Gamma Override value:
For details on the quiet: option which was added to this method in 3ds Max 8, please see Quiet Mode
The method will return True on success or False if the saving failed (for example if attempting to overwrite an existing read-only file) in 3ds Max 8 and higher.
Closes the bitmap file associated with the bitmap if it is open for output. A bitmap file is opened for output when you call save on the bitmap value the first time. If a Virtual Frame Buffer (Rendered Frame Window) associated with the bitmap is open, it will be closed. This function also frees all memory allocated by the bitmap, including the internal pixel frame buffer. If you are generating many bitmaps, say in a rendering loop, you can use the close() function to free these often large amounts of memory, that won’t otherwise be released until the next garbage collection.
Frees the memory used by the bitmap value without waiting for garbage collection.
Available in 3ds Max 9 and higher.
Copies the source bitmap to the destination bitmap. If the size of the two bitmaps is different, the image will be scaled to fit the destination bitmap.
Position multi-frame file (avi, flc, etc.) to frame frame . This method is permitted only on load-only bitmaps. The frame number is 0-based for inherently multi-frame files, such as .avi and .mov. Updates VFB if open.
Retrieve a sequence of pixels from a row in the bitmap as an array of color values.
The coord_point2 argument specifies the starting pixel coordinate with [0,0] at the top-left-hand pixel.
The .x component of the Point2 coordinate is the column, and the .y component is the row.
The sequence must come from one row only; you cannot retrieve a sequence of pixels that spans multiple rows.
Using any out of-bounds coordinates or retrieving over row boundaries will fail and yield an empty array.
The optional linear: keyword parameter introduced in 3ds Max 2014 can be set to True to access linear values with Gamma of 1.0, or False to access raw data (default, old behavior prior to 3ds Max 2014).
Sets the sequence of pixels in a row in the bitmap starting at the Point2 coordinate to the values in the given array. The .x component of the Point2 coordinate is the column, and the .y component is the row. The number of pixels to set is taken from the size of the array. As with getPixels() , you cannot set pixel sequences across a row boundary.
Retrieve a row of pixels as an array of palette index numbers. The coord_point2 argument specifies the starting pixel coordinate with 0,0 at the top-left-hand pixel. The index numbers are origin 0.
that this is in keeping with indexed color conventions but not MAXScript's. Take care accessing any retrieved palette array using these numbers because the retrieved palette is returned as a MAXScript array and these arrays use 1-based indexes. You cannot get pixels sequences that cross row boundaries.
Sets the row of pixels starting at the Point2 coordinate to the color indexes in the given array. The number of pixels to set is taken from the size of the array. The color indexes are zero-based. You cannot set pixels sequences that cross row boundaries.
Retrieves the g-buffer channel data for the named channel for the pixel specified by 2D coordinate. The chan_name argument specifies the channel identifier, chosen from the following:
#zDepth #matID #objectID #UVCoords #normal #unClamped #coverage #node #mask #shaderColor #shaderTransparency #velocity #weight
If the bitmap contains the requested channel, the returned value is always an array of values, one for each layer present in the channel at that pixel, ordered from front to back. If the bitmap does not contain the requested channel, the function returns the value undefined . Typically, you get bitmaps containing channels by opening .rla files or using the MAXScript render() function with the channels: parameter supplied. You will get multiple values in the array if the front objects have any transparency.
The type of values returned in the array depend of the channel, as follows:
#zDepth: <float> #matID: <integer> #objectID: <integer> #UVCoords: <point2> #normal: <point3> #unClamped: <color> #coverage: <float> #node: <node> #shaderColor: <color> #shaderTransparency: <color> #velocity: <point2> #weight: <color>
See the 3ds Max Software Development Kit Help file for information on the data stored in the g-buffer channels.
getChannelAsMask<bitmap> <chan_name> [to:<bitmap>] \ [fileName:"filename_string"] [pixelAspect:<float>] \ [gamma:<float>] [layer:<integer>] [invert:<boolean>] \ [node:<node> |objectID:<integer> |matID:<integer>] \ [velocity:#angle | #magnitude] | [angle:<float>]
Builds and returns a separate 8-bit gray-level bitmap, suitable for use as a mask in materials, maps, effects, and so on. This bitmap corresponds roughly to the display you see in the visual frame buffer if you select a g-buffer channel to view. In addition, you can cause this mask to be masked itself to a selected node, object ID or material ID. The parameters are as follows:
The source bitmap containing the source g-buffer channel data.
The channel from which to generate a mask. The chan_name values are as described for the getChannel() method.
Specifies an existing bitmap to write the mask into. Its width and height must match the source bitmap.
Specifies the file name associated with the generated bitmap.
Specifies the generated bitmap's gamma value.
Specifies the generated bitmap's pixel aspect. Note that this is the aspect of the pixel, not the aspect of the bitmap image.
Specifies the channel layer of the source bitmap to extract data from. Defaults to 1.
If true , inverts the generated bitmap. Defaults to . false
Specifies a sub-mask. If one of these parameters is supplied, the generated mask is clipped to contain data only in pixels where the given node, objectID or materialID is visible. To use this sub-masking, you must ensure the #node , #objectID or #matID channel is present in the source bitmap. Further, if the #coverage channel is present in the source bitmap, the sub-mask is anti-aliased by the coverage data.
These parameters can only be specified if the selected channel is #velocity . The default velocity parameter value is #magnitude . These parameters control the generated bitmap as follows:
Generated bitmap pixel values are proportional to angle of pixel movement direction, with an angle of direction of 0 degrees (horizontal to the right) mapping to a luminance value of 0, 180 degrees mapping to a luminance value of 127, and 360 degrees mapping to a luminance value of 255.
Generated bitmap pixel values are proportional to velocity magnitude. High velocities are darker than low velocities.
Generated bitmap pixel values are proportional to movement direction deviation from the given angle, with a luminance value of 255 at the exact angle and falling off to a luminance value of 0 at 10 degrees from the specified angle. The specified angle is relative to 0 being horizontal to the right.
CompareBitmaps {<filename>File1 | <bitmap>bitmap1} {<filename>File2 | <bitmap>bitmap2}\ <int>tolerance(# different pixels) <int>variation(0-255)\ useAlpha:<boolean>errorMsg:<&string>
In 3ds Max 9 and higher, returns true if the bitmaps compare as the same, false if not.
More than'tolerance' number of pixels must be different before the comparison fails.
Two pixels are considered the same if the difference in each component value is less than or equal to 'variation'.
If useAlpha is true, the alpha component value is also tested. If false (the default), the alpha component is not tested.
If specified, the errorMsg keyword variable (passed by reference) will contain an error message.
pasteBitmap <src_bitmap> <dest_bitmap> (<src_box2> | <src_point2>) <dest_point2> \ [maskColor:<color>type:{#paste|#composite|#blend|#function}] \ [function:<composite_fn>] [alphaMultiplier:<float>]
Copies a block of pixels from the source bitmap to the destination bitmap.
Available in 3ds Max 2008 and higher. Previously available in the Avguard Extensions.
The position of the source block is specified by src_box2 or src_point2, and the destination by dest_point2.
The width and height of the block is specifed by src_box2 or, if src_point2 is specified, by the remaining size of the source bitmap.
The width and height will be clamped to prevent either source or target overruns.
If maskColor: is supplied, pixels with this color in src_bitmap are not copied to dest_bitmap.
If type: is #paste (the default), the source is pasted on the destination ignoring all alpha.
If type: is #composite , the source alpha of the source is used: clamp (R = S + D * (1-S.alpha))
If type: is #blend , the source alpha of the source is used: R = S * S.alpha + D * (1-S.alpha)
For both type:#composite and type:#blend , R.alpha = S.alpha + D.alpha * (1-S.alpha)
The type:#composite would typically be used for pre-multiplied alpha images.
If type: is #composite or #blend , the source alpha is multiplied by the alphaMultiplier: value, which defaults to a value of 1.0 if not supplied.
If type: is #function , an optional function: parameter can specify a user-defined function taking 4 arguments - the source pixel color, the source pixel location, the second source pixel color and second source pixel location. The second source is the destimation bitmap. The return result of the function is stored in the destination bitmap's pixel.
Only RGBA information is copied - no channel data is copied.
CUSTOM COMPOSITING EXAMPLE |
resetMaxFile #noPrompt--start a new scene --Create a teapot and two slightly offset target cameras theTeapot = teapot wirecolor:white segs:10 theTarget1 = targetObject pos:[-1,0,10] theCamera1 = TargetCamera pos:[-10,-130,30] target:theTarget1 theTarget2 = targetObject pos:[1,0,10] theCamera2 = TargetCamera pos:[10,-130,30] target:theTarget2 --Create two bitmaps to render and process b1 = bitmap 320 240 b2 = bitmap 320 240 --Render the two cameras into the two bitmaps render camera:theCamera1 to:b1 vfb:off render camera:theCamera2 to:b2 vfb:off --This is the custom compositing function: fn compfn c1 p1 c2 p2 = ( res = c2--the result will contain the G and B of b2 res.r = c1.r--but the R from b1 res--then we return the resulting color value ) --Perform the compositing using the above function: pastebitmap b1 b2 [0,0] [0,0] type:#function function:compfn display b2 |
This method is typically 3 to 5 times faster than using getPixels/SetPixels in a MAXScript loop, depending on the complexity of the custom function. For an example of modifying a single bitmap using this method, see the third example in the Never get a single pixel when you can get a whole line topic of the MAXScript Frequently Asked Questions. |
Returns information onthe specified bitmap file as a13 element array.Available in 3ds Max 2008 and higher. Previously available in the Avguard Extensions.
1. Expanded bitmap file name as String
5. Number of bits for each RGB component value as Integer
6. Number of bits for alpha component as Integer.
7. The aspect ratio of the bitmap as Float
8. The gamma of the bitmap as Float
9. Whether the bitmap has alpha as a Boolean
12. The bitmap type (from BitmapInfo::Type()) as Integer. See topic "Bitmap Types" in the SDK help file for more info on the bitmap types.
13. The bitmap flags (from BitmapInfo::Flags()) as Integer. See topic "Bitmap Flags" in the SDK help file for more info on the meaning of each bit.
forceReloadBitmapFile <bitmap>
NEW in 3ds Max 2015: Forces the reloading of the Bitmap File associated with the specified bitmap.
<boolean>registerFileChangedFunction <bitmap> <callback_functions>
NEW in 3ds Max 2015: Registers a File Change Callback Function for the bitmap specified by the first argument.
The second argument must be a MAXScript function expecting one argument.
Returns True on success, False on failure.
Sets Silent mode on or off. If Silent mode is off, any errors occurring during bitmap input or output will result in an error message dialog being displayed by the 3ds Max bitmap I/O routines. If Silent mode is on, error message dialogs are not displayed. Returns a boolean signifying the prior Silent mode state.
The Silent mode state is an internal 3ds Max state, and other 3ds Max plug-ins can turn this state on or off. It is recommended that if you use this method that you turn the state on or off saving the return value, perform the bitmap input or output, and then restore the state to its original value.
Returns a boolean signifying the Silent mode state.
Displays a 3ds Max bitmap save dialog and returns the fully-specified file path name as a string.
Returns undefined if the user cancels out of the bitmap save dialog.
If the optional gamma: keyword is provided in 3ds Max 2014 and higher, the by-reference variable passed as parameter will be set to the gamma mode value: #auto , #default or a Float gamma override value.
If the optional metadata: keyword is provided in 3ds Max 2014 and higher, the by-reference variable passed as parameter will be set to the BitmapInfo expressed as an array of values that can be passed to the save() function's metadata: optional keyword. See Bitmap Gamma and MAXScript for details.
FOR EXAMPLE: |
bitmap.filename = SelectSaveBitmap caption:"Select a file" gamma:&gma metadata:&data if (bitmap.filename) do save bitmap gamma:gma metadata:data |
Frees up all the memory used by the image file bitmap caches. This is useful if memory is fragmented with a lot of different bitmaps and you want to have just the ones currently active reloaded.
getBitmapOpenFileName [caption:<title>] [filename:<seed_filename_string>] [metadata:&dataArray] getBitmapSaveFileName [caption:<title>] [filename:<seed_filename_string>] [metadata:&dataArray]
Displays the bitmap file selection dialog.
Both functions return a fully-specified file path name or undefined if the user cancels out.
If an existing file name is selected using the getBitmapSaveFileName() function, a File Exists/Confirm Overwrite dialog will be displayed.
If the optional metadata: keyword is provided in 3ds Max 2014 and higher, the by-reference variable passed as parameter will be set to the BitmapInfo expressed as an array of values that can be passed to the save() function's metadata: optional keyword. See Bitmap Gamma and MAXScript for details.
When you open a bitmap file, an entire frame is loaded into memory. When you are finished processing a bitmap, it is a good idea to either call close() on the bitmap or assign the value undefined to the variable storing the bitmap value, and then manually run garbage collection ( gc light:true ), so that it’s memory can be released. Another technique for conserving memory when using the render() or getChannelAsMask() functions repeatedly is to use the to:<bitmap> keyword argument which allows those functions to overwrite an existing bitmap’s pixel image with the new rendering or mask.
There is currently no access to the properties associated with some of the bitmap output plug-ins. This means that you cannot set the codec used for .avi files. The properties used are the properties that were last used when saving that file type in 3ds Max.
The following script shows how to properly create and save a multi-frame image file in AVI format.
While the frame:i keyword argument to the save() method is optional for AVI files (they would advance automatically after each frame), Quicktime MOV files require it to save correctly. Otherwise, each rendered frame will overwrite the first frame in the file and the MOV would end up only one frame long.
The following script reads a bitmap file, and outputs a script to Listener that implements a function that will recreate the same bitmap. This function can then be copied into your script. This is useful for building button images in MAXScript, so that you don't need to distribute bitmap files along with your script.
Also see the example inPoint3 Values for another usage of class Bitmap.