public class BmpOptions extends ImageOptionsBase
The API for BMP and DIB raster image format creation options provides developers with a versatile toolset for generating custom Bitmap (BMP) and Device Independent Bitmap (DIB) images. With this API, you can precisely define image characteristics such as bits per pixel, compression level and compression type, tailoring the output to meet specific requirements. This feature-rich API empowers developers to create high-quality, customized raster images with ease and flexibility for diverse applications.
This example demonstrates the use of different classes from SaveOptions Namespace for export purposes. An image of type Gif is loaded into an instance of Image and then exported out to several formats.
String dir = "c:\\temp\\";
//Load an existing image (of type Gif) in an instance of Image class
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.gif");
try {
//Export to BMP file format using the default options
image.save(dir + "output.bmp", new com.aspose.imaging.imageoptions.BmpOptions());
//Export to JPEG file format using the default options
image.save(dir + "output.jpeg", new com.aspose.imaging.imageoptions.JpegOptions());
//Export to PNG file format using the default options
image.save(dir + "output.png", new com.aspose.imaging.imageoptions.PngOptions());
//Export to TIFF file format using the default options
image.save(dir + "output.tif", new com.aspose.imaging.imageoptions.TiffOptions(com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat.Default));
} finally {
image.dispose();
}
| Constructor and Description |
|---|
BmpOptions()
Initializes a new instance of the
BmpOptions class. |
BmpOptions(BmpOptions bmpOptions)
Initializes a new instance of the
BmpOptions class. |
| Modifier and Type | Method and Description |
|---|---|
int |
getBitsPerPixel()
Gets or sets the image bits per pixel count.
|
long |
getCompression()
Gets the compression type.
|
void |
setBitsPerPixel(int value)
Gets or sets the image bits per pixel count.
|
void |
setCompression(long value)
Sets the compression type.
|
deepClone, getBufferSizeHint, getExifData, getFullFrame, getMultiPageOptions, getPalette, getProgressEventHandler, getResolutionSettings, getSource, getVectorRasterizationOptions, getXmpData, isKeepMetadata, setBufferSizeHint, setExifData, setFullFrame, setKeepMetadata, setMultiPageOptions, setPalette, setProgressEventHandler, setResolutionSettings, setSource, setVectorRasterizationOptions, setXmpData, trySetMetadataclose, dispose, getDisposedpublic BmpOptions()
Initializes a new instance of the BmpOptions class.
The following example loads a BMP image and saves it back to BMP using various save options.
String dir = "c:\\temp\\";
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.bmp");
try {
com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
// Create BmpOptions
com.aspose.imaging.imageoptions.BmpOptions saveOptions = new com.aspose.imaging.imageoptions.BmpOptions();
// Use 8 bits per pixel to reduce the size of the output image.
saveOptions.setBitsPerPixel(8);
// Set the closest 8-bit color palette which covers the maximal number of image pixels, so that a palettized image
// is almost visually indistinguishable from a non-palletized one.
saveOptions.setPalette(com.aspose.imaging.ColorPaletteHelper.getCloseImagePalette(rasterImage, 256));
// Save without compression.
// You can also use RLE-8 compression to reduce the size of the output image.
saveOptions.setCompression(com.aspose.imaging.fileformats.bmp.BitmapCompression.Rgb);
// Set the horizontal and vertical resolution to 96 dpi.
saveOptions.setResolutionSettings(new com.aspose.imaging.ResolutionSetting(96.0, 96.0));
image.save(dir + "sample.bmpoptions.bmp", saveOptions);
} finally {
image.dispose();
}
public BmpOptions(BmpOptions bmpOptions)
Initializes a new instance of the BmpOptions class.
bmpOptions - The BMP options.public int getBitsPerPixel()
Gets or sets the image bits per pixel count.
public void setBitsPerPixel(int value)
Gets or sets the image bits per pixel count.
value - The image bits per pixel count.The following example loads a BMP image and saves it back to BMP using various save options.
String dir = "c:\\temp\\";
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.bmp");
try {
com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
// Create BmpOptions
com.aspose.imaging.imageoptions.BmpOptions saveOptions = new com.aspose.imaging.imageoptions.BmpOptions();
// Use 8 bits per pixel to reduce the size of the output image.
saveOptions.setBitsPerPixel(8);
// Set the closest 8-bit color palette which covers the maximal number of image pixels, so that a palettized image
// is almost visually indistinguishable from a non-palletized one.
saveOptions.setPalette(com.aspose.imaging.ColorPaletteHelper.getCloseImagePalette(rasterImage, 256));
// Save without compression.
// You can also use RLE-8 compression to reduce the size of the output image.
saveOptions.setCompression(com.aspose.imaging.fileformats.bmp.BitmapCompression.Rgb);
// Set the horizontal and vertical resolution to 96 dpi.
saveOptions.setResolutionSettings(new com.aspose.imaging.ResolutionSetting(96.0, 96.0));
image.save(dir + "sample.bmpoptions.bmp", saveOptions);
} finally {
image.dispose();
}
public long getCompression()
Gets the compression type. The default compression type is BitmapCompression.Bitfields, that allows saving a BmpImage with transparency.
Decompress BMP image which was previously compressed using DXT1 compression algorithm.
try (Image image = Image.load("CompressedTiger.bmp"))
{
image.save("DecompressedTiger.bmp", new BmpOptions());
}
}
{
public void setCompression(long value)
Sets the compression type. The default compression type is BitmapCompression.Bitfields, that allows saving a BmpImage with transparency.
value - the compression type.The following example loads a BMP image and saves it back to BMP using various save options.
String dir = "c:\\temp\\";
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.bmp");
try {
com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
// Create BmpOptions
com.aspose.imaging.imageoptions.BmpOptions saveOptions = new com.aspose.imaging.imageoptions.BmpOptions();
// Use 8 bits per pixel to reduce the size of the output image.
saveOptions.setBitsPerPixel(8);
// Set the closest 8-bit color palette which covers the maximal number of image pixels, so that a palettized image
// is almost visually indistinguishable from a non-palletized one.
saveOptions.setPalette(com.aspose.imaging.ColorPaletteHelper.getCloseImagePalette(rasterImage, 256));
// Save without compression.
// You can also use RLE-8 compression to reduce the size of the output image.
saveOptions.setCompression(com.aspose.imaging.fileformats.bmp.BitmapCompression.Rgb);
// Set the horizontal and vertical resolution to 96 dpi.
saveOptions.setResolutionSettings(new com.aspose.imaging.ResolutionSetting(96.0, 96.0));
image.save(dir + "sample.bmpoptions.bmp", saveOptions);
} finally {
image.dispose();
}
Copyright (c) 2008-2025 Aspose Pty Ltd. All Rights Reserved.