Packages

 

com.aspose.imaging.imageoptions

Class BmpOptions

  • All Implemented Interfaces:
    com.aspose.ms.System.IDisposable, Closeable, AutoCloseable


    public class BmpOptions
    extends ImageOptionsBase

    The bmp file format creation options.

    Code example:

    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 Detail

      • BmpOptions

        public BmpOptions()

        Initializes a new instance of the BmpOptions class.

        Code example:

        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();
        }
        

      • BmpOptions

        public BmpOptions(BmpOptions bmpOptions)

        Initializes a new instance of the BmpOptions class.

        Parameters:
        bmpOptions - The BMP options.
    • Method Detail

      • getBitsPerPixel

        public int getBitsPerPixel()

        Gets or sets the image bits per pixel count.

        Returns:
        The image bits per pixel count.
      • setBitsPerPixel

        public void setBitsPerPixel(int value)

        Gets or sets the image bits per pixel count.

        Parameters:
        value - The image bits per pixel count.
        Code example:

        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();
        }
        

      • getCompression

        public long getCompression()

        Gets or sets the compression.

        Returns:
        The compression.
        Code example:

        Decompress BMP image which was previously compressed using DXT1 compression algorithm.


            try (Image image = Image.load("CompressedTiger.bmp"))
            {
                image.save("DecompressedTiger.bmp", new BmpOptions());
            }
        }
        
        {
        

      • setCompression

        public void setCompression(long value)

        Gets or sets the compression.

        Parameters:
        value - The compression.
        Code example:

        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();
        }