Printing and Exporting Figures with MATLAB | ![]() ![]() |
Preserving Colors in Exported Figures
The number of colors used in your exported figure depends on the bit depth of the format you choose. If file size is not critical, make sure you choose a format with a bit depth that supports the number of colors in your displayed figure.
You cannot change the bit depth of a format. See the first column of Table 4-1, Export Formats and Export-Only Options, for the bit depth each bitmap format produces.
Note The vector formats in the table do not indicate bit depths. See "Bit Depths and Vector Formats for more information. |
Bit depth is the number of bits a format uses to store each pixel. This determines the number of colors the image can contain. An 8-bit image uses 8 bits per pixel (bpp), enabling it to define 28, or 256 unique colors. The other supported bit depths are: 1-bit (2 colors), 4-bit (16 colors), and 24-bit (16 million colors).
Too Few Colors
If the format supports fewer colors than are contained in the figure, some colors will be dithered or mapped to approximate matches. This can result in reduced graduation of shading, and in some cases to wrong colors being used. The figure below shows the same figure (which contains many colors) exported using formats with bit depths of 24- and 8-bits per pixel. Since the displayed figure contained more colors than the 256 available in an 8-bit image, the quality of the exported file suffers. The 24-bit format was adequate for this figure.
Figure 4-5: Same Figure Saved Using Different Bit Depths
Multiple Bit Depths for Same Format
Some of the supported formats come in versions that have different bit depths. For example, the different versions for BMP files can produce files with 1-, 8-, or 24 bits per pixel. Be sure to choose the version that produces the desired bit depth. Check the first column of Table 4-1, Export Formats and Export-Only Options, to see if there are choices of bit depths for the format you want to use.
Bit Depths and Vector Formats
Bit depths are not normally associated with vector formats. Normally the color of objects is specified by the drawing commands. However, if you save image objects in vector formats, they are always saved as bitmaps, regardless of the rendering method used. These bitmaps use a bit depth.
Vector files will also have an associated bit depth if you create them using the OpenGL or Z-buffer renderer. In this case, everything in the figure is saved as a bitmap.
The table below summarizes when a bit depth is used in a vector file, and what its value is.
To summarize, bit depth has little effect on the size of a vector file unless the figure contains an image, or the renderer is set to OpenGL or Z-buffer.
![]() | Bitmap and Vector Formats | Getting the Best Results With Bitmap Formats | ![]() |