Packages

 

com.aspose.imaging.fileformats.bmp

Class BmpImage

  • All Implemented Interfaces:
    IObjectWithBounds, IRasterImageArgb32PixelLoader, IRasterImageRawDataLoader, com.aspose.imaging_internal.IPixelsSaver, com.aspose.imaging_internal.progressmanagement.IProgressEventHandler, com.aspose.imaging_internal.progressmanagement.IProgressInformer, com.aspose.ms.System.IDisposable, Closeable, AutoCloseable


    public final class BmpImage
    extends RasterCachedImage

    A bmp image (supports BMP, DIB formats).

    Code example:

    The following example shows how to create a BMP image of the specified size.


    String dir = "c:\\temp\\";
    
    // Create a BMP image 100 x 100 px.
    com.aspose.imaging.fileformats.bmp.BmpImage bmpImage = new com.aspose.imaging.fileformats.bmp.BmpImage(100, 100);
    try {
        // Fill the image with a simple linear red-black gradient.
        int width = bmpImage.getWidth();
        int height = bmpImage.getHeight();
        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                int hue = (255 * x) / width;
                bmpImage.setPixel(x, y, com.aspose.imaging.Color.fromArgb(255, hue, 0, 0));
            }
        }
    
        java.io.OutputStream stream = new java.io.FileOutputStream(dir + "output.bmp");
        try {
            bmpImage.save(stream);
        } finally {
            stream.close();
        }
    } finally {
        bmpImage.dispose();
    }
    

    • Constructor Detail

      • BmpImage

        public BmpImage(String path)

        Initializes a new instance of the BmpImage class.

        Parameters:
        path - The path to load image from and initialize pixel and palette data with.
        Throws:
        com.aspose.ms.System.ArgumentNullException - raster image is null;rasterImage
        BmpImageException - The height should be positive.
        com.aspose.ms.System.ArgumentException - Palette should be specified for images with 8 bits per pixel or less.;palette
        Code example:

        The example shows how to load a BmpImage from a file.


        String dir = "c:\\temp\\";
        
        // Load a BMP image from a file.
        // The source pixels will be converted to 32-bpp format if required.
        com.aspose.imaging.fileformats.bmp.BmpImage bmpImage = new com.aspose.imaging.fileformats.bmp.BmpImage(dir + "sample.bmp");
        try {
            // Do some image processing.
            // Save to another BMP file.
            bmpImage.save(dir + "sample.output.32bpp.bmp");
        } finally {
            bmpImage.dispose();
        }
        

      • BmpImage

        public BmpImage(String path,
                        int bitsPerPixel,
                        long compression,
                        double horizontalResolution,
                        double verticalResolution)

        Initializes a new instance of the BmpImage class.

        Parameters:
        path - The path to load image from and initialize pixel and palette data with.
        bitsPerPixel - The bits per pixel.
        compression - The compression to use.
        horizontalResolution - The horizontal resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.
        verticalResolution - The vertical resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.
        Throws:
        com.aspose.ms.System.ArgumentNullException - The raster image cannot be null;rasterImage
        BmpImageException - The height should be positive.
        com.aspose.ms.System.ArgumentException - Palette should be specified for images with 8 bits per pixel or less.;palette
        Code example:

        The example shows how to load a BmpImage from a file with the specified bit depth and resolution.


        String dir = "c:\\temp\\";
        
        // Load a BMP image from a file.
        // The source pixels will be converted to 24-bpp format if required.
        // The resolution will be set to 96 dpi.
        com.aspose.imaging.fileformats.bmp.BmpImage bmpImage =
                new com.aspose.imaging.fileformats.bmp.BmpImage(dir + "sample.bmp", 24, com.aspose.imaging.fileformats.bmp.BitmapCompression.Rgb, 96.0, 96.0);
        try {
            // Do some image processing.
            // Save to another BMP file.
            bmpImage.save(dir + "sample.output.24bpp.96dpi.bmp");
        } finally {
            bmpImage.dispose();
        }
        

      • BmpImage

        public BmpImage(InputStream stream)

        Initializes a new instance of the BmpImage class.

        Parameters:
        stream - The stream to load image from and initialize pixel and palette data with.
        Throws:
        com.aspose.ms.System.ArgumentNullException - The raster image cannot be null;rasterImage
        BmpImageException - The height should be positive.
        com.aspose.ms.System.ArgumentException - Palette should be specified for images with 8 bits per pixel or less.;palette
        Code example:

        The example shows how to load a BmpImage from a file stream.


        String dir = "c:\\temp\\";
        
        // Load a BMP image from a file stream.
        // The source pixels will be converted to 32-bpp format if required.
        java.io.InputStream stream = new java.io.FileInputStream(dir + "sample.bmp");
        try {
            com.aspose.imaging.fileformats.bmp.BmpImage bmpImage = new com.aspose.imaging.fileformats.bmp.BmpImage(stream);
            try {
                // Do some image processing.
                // Save to another BMP file.
                bmpImage.save(dir + "sample.output.32bpp.bmp");
            } finally {
                bmpImage.dispose();
            }
        } finally {
            stream.close();
        }
        

      • BmpImage

        public BmpImage(InputStream stream,
                        int bitsPerPixel,
                        long compression,
                        double horizontalResolution,
                        double verticalResolution)

        Initializes a new instance of the BmpImage class.

        Parameters:
        stream - The stream to load image from and initialize pixel and palette data with.
        bitsPerPixel - The bits per pixel.
        compression - The compression to use.
        horizontalResolution - The horizontal resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.
        verticalResolution - The vertical resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.
        Throws:
        com.aspose.ms.System.ArgumentNullException - The raster image cannot be null;rasterImage
        BmpImageException - The height should be positive.
        com.aspose.ms.System.ArgumentException - Palette should be specified for images with 8 bits per pixel or less.;palette
        Code example:

        The example shows how to load a BmpImage from a file stream with the specified bit depth and resolution.


        String dir = "c:\\temp\\";
        
        // Load a BMP image from a file stream.
        // The source pixels will be converted to 24-bpp format if required.
        // The resolution will be set to 96 dpi.
        java.io.InputStream stream = new java.io.FileInputStream(dir + "sample.bmp");
        try {
            com.aspose.imaging.fileformats.bmp.BmpImage bmpImage =
                    new com.aspose.imaging.fileformats.bmp.BmpImage(stream, 24, com.aspose.imaging.fileformats.bmp.BitmapCompression.Rgb, 96.0, 96.0);
            try {
                // Do some image processing.
                // Save to another BMP file.
                bmpImage.save(dir + "sample.output.24bpp.96dpi.bmp");
            } finally {
                bmpImage.dispose();
            }
        } finally {
            stream.close();
        }
        

      • BmpImage

        public BmpImage(RasterImage rasterImage)

        Initializes a new instance of the BmpImage class.

        Parameters:
        rasterImage - The image to initialize pixel and palette data with.
        Throws:
        com.aspose.ms.System.ArgumentNullException - The raster image cannot be null;rasterImage
        BmpImageException - The height should be positive.
        com.aspose.ms.System.ArgumentException - Palette should be specified for images with 8 bits per pixel or less.;palette
        Code example:

        The example shows how to load a BmpImage from another instance of RasterImage.


        String dir = "c:\\temp\\";
        
        // Create a new PNG image.
        com.aspose.imaging.imageoptions.PngOptions createOptions = new com.aspose.imaging.imageoptions.PngOptions();
        createOptions.setSource(new com.aspose.imaging.sources.StreamSource(new java.io.ByteArrayInputStream(new byte[0]), true));
        com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) com.aspose.imaging.Image.create(createOptions, 100, 100);
        try {
            // Fill the entire PNG image in red.
            com.aspose.imaging.Graphics gr = new com.aspose.imaging.Graphics(rasterImage);
            com.aspose.imaging.brushes.SolidBrush brush = new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getRed());
            gr.fillRectangle(brush, rasterImage.getBounds());
        
            // Create a BMP image based on the PNG image.
            // The source pixels will be converted to 32-bpp format if required.
            com.aspose.imaging.fileformats.bmp.BmpImage bmpImage = new com.aspose.imaging.fileformats.bmp.BmpImage(rasterImage);
            try {
                // Save to a BMP file
                bmpImage.save(dir + "output.32bpp.bmp");
            } finally {
                bmpImage.dispose();
            }
        } finally {
            rasterImage.dispose();
        }
        

      • BmpImage

        public BmpImage(RasterImage rasterImage,
                        int bitsPerPixel,
                        long compression,
                        double horizontalResolution,
                        double verticalResolution)

        Initializes a new instance of the BmpImage class.

        Parameters:
        rasterImage - The image to initialize pixel and palette data with.
        bitsPerPixel - The bits per pixel.
        compression - The compression to use.
        horizontalResolution - The horizontal resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.
        verticalResolution - The vertical resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.
        Throws:
        com.aspose.ms.System.ArgumentNullException - The raster image cannot be null;rasterImage
        BmpImageException - The height should be positive.
        com.aspose.ms.System.ArgumentException - Palette should be specified for images with 8 bits per pixel or less.;palette
        Code example:

        The example shows how to load a BmpImage from another instance of RasterImage with the specified bit depth and compression.


        String dir = "c:\\temp\\";
        
        // Create a new PNG image.
        com.aspose.imaging.imageoptions.PngOptions createOptions = new com.aspose.imaging.imageoptions.PngOptions();
        createOptions.setSource(new com.aspose.imaging.sources.StreamSource(new java.io.ByteArrayInputStream(new byte[0]), true));
        com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) com.aspose.imaging.Image.create(createOptions, 100, 100);
        try {
            // Fill the entire PNG image in red.
            com.aspose.imaging.Graphics gr = new com.aspose.imaging.Graphics(rasterImage);
            com.aspose.imaging.brushes.SolidBrush brush = new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getRed());
            gr.fillRectangle(brush, rasterImage.getBounds());
        
            // Create a BMP image based on the PNG image.
            // The source pixels will be converted to 24-bpp format if required.
            // The resolution will be set to 96 dpi.
            com.aspose.imaging.fileformats.bmp.BmpImage bmpImage = new com.aspose.imaging.fileformats.bmp.BmpImage(rasterImage, 24, com.aspose.imaging.fileformats.bmp.BitmapCompression.Rgb, 96.0, 96.0);
            try {
                // Save to a BMP file
                bmpImage.save(dir + "output.24bpp.96dpi.bmp");
            } finally {
                bmpImage.dispose();
            }
        } finally {
            rasterImage.dispose();
        }
        

      • BmpImage

        public BmpImage(int width,
                        int height)

        Initializes a new instance of the BmpImage class.

        Parameters:
        width - The image width.
        height - The image height.
        Throws:
        BmpImageException - The height should be positive.
        com.aspose.ms.System.ArgumentException - Palette should be specified for images with 8 bits per pixel or less.;palette
        Code example:

        The example shows how to create a BmpImage of the specified size.


        String dir = "c:\\temp\\";
        
        // Create a 32-bpp BMP image of 100 x 100 px.
        com.aspose.imaging.fileformats.bmp.BmpImage bmpImage = new com.aspose.imaging.fileformats.bmp.BmpImage(100, 100);
        try {
            // Fill the entire image in red.
            com.aspose.imaging.Graphics gr = new com.aspose.imaging.Graphics(bmpImage);
            com.aspose.imaging.brushes.SolidBrush brush = new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getRed());
            gr.fillRectangle(brush, bmpImage.getBounds());
        
            // Save to a BMP file
            bmpImage.save(dir + "output.bmp");
        } finally {
            bmpImage.dispose();
        }
        

      • BmpImage

        public BmpImage(int width,
                        int height,
                        int bitsPerPixel,
                        IColorPalette palette)

        Initializes a new instance of the BmpImage class.

        Parameters:
        width - The image width.
        height - The image height.
        bitsPerPixel - The bits per pixel.
        palette - The color palette.
        Throws:
        BmpImageException - The height should be positive.
        com.aspose.ms.System.ArgumentException - Palette should be specified for images with 8 bits per pixel or less.;palette
        Code example:

        The example shows how to create a BmpImage of the specified size with the specified palette.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.Color[] paletterColors = new com.aspose.imaging.Color[]
                {
                        com.aspose.imaging.Color.getRed(),
                        com.aspose.imaging.Color.getGreen(),
                };
        
        // Create a monochrome palette which contains only red and green colors.
        com.aspose.imaging.IColorPalette palette = new com.aspose.imaging.ColorPalette(paletterColors);
        
        // Create a monochrome 1-bpp BMP image of 100 x 100 px.
        com.aspose.imaging.fileformats.bmp.BmpImage bmpImage = new com.aspose.imaging.fileformats.bmp.BmpImage(100, 100, 1, palette);
        try {
            com.aspose.imaging.Graphics gr = new com.aspose.imaging.Graphics(bmpImage);
        
            // Fill the upper half of the image in red.
            com.aspose.imaging.brushes.SolidBrush redBrush = new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getRed());
            gr.fillRectangle(redBrush, new com.aspose.imaging.Rectangle(0, 0, bmpImage.getWidth(), bmpImage.getHeight() / 2));
        
            // Fill the lower half of the image in green.
            com.aspose.imaging.brushes.SolidBrush greenBrush = new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getGreen());
            gr.fillRectangle(greenBrush, new com.aspose.imaging.Rectangle(0, bmpImage.getHeight() / 2, bmpImage.getWidth(), bmpImage.getHeight() / 2));
        
            // Save to BMP
            bmpImage.save(dir + "output.monochrome.bmp");
        } finally {
            bmpImage.dispose();
        }
        

      • BmpImage

        public BmpImage(int width,
                        int height,
                        int bitsPerPixel,
                        IColorPalette palette,
                        long compression,
                        double horizontalResolution,
                        double verticalResolution)

        Initializes a new instance of the BmpImage class.

        Parameters:
        width - The image width.
        height - The image height.
        bitsPerPixel - The bits per pixel.
        palette - The color palette.
        compression - The compression to use.
        horizontalResolution - The horizontal resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.
        verticalResolution - The vertical resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.
        Throws:
        BmpImageException - The height should be positive.
        com.aspose.ms.System.ArgumentException - Palette should be specified for images with 8 bits per pixel or less.;palette
        Code example:

        The example shows how to create a BmpImage using various options.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.Color[] paletterColors = new com.aspose.imaging.Color[]
                {
                        com.aspose.imaging.Color.getRed(),
                        com.aspose.imaging.Color.getGreen(),
                };
        
        // Create a monochrome palette which contains only red and green colors.
        com.aspose.imaging.IColorPalette palette = new com.aspose.imaging.ColorPalette(paletterColors);
        
        // Create a monochrome 1-bpp BMP image of 100 x 100 px.
        // The horizontal and vertical resolution will be set to 96 dpi.
        com.aspose.imaging.fileformats.bmp.BmpImage bmpImage = new com.aspose.imaging.fileformats.bmp.BmpImage(100, 100, 1, palette, com.aspose.imaging.fileformats.bmp.BitmapCompression.Rgb, 96.0, 96.0);
        try {
            com.aspose.imaging.Graphics gr = new com.aspose.imaging.Graphics(bmpImage);
        
            // Fill the upper half of the image in red.
            com.aspose.imaging.brushes.SolidBrush redBrush = new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getRed());
            gr.fillRectangle(redBrush, new com.aspose.imaging.Rectangle(0, 0, bmpImage.getWidth(), bmpImage.getHeight() / 2));
        
            // Fill the lower half of the image in green.
            com.aspose.imaging.brushes.SolidBrush greenBrush = new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getGreen());
            gr.fillRectangle(greenBrush, new com.aspose.imaging.Rectangle(0, bmpImage.getHeight() / 2, bmpImage.getWidth(), bmpImage.getHeight() / 2));
        
            // Save to a BMP file
            bmpImage.save(dir + "output.monochrome.96dpi.bmp");
        } finally {
            bmpImage.dispose();
        }
        

    • Method Detail

      • getBitmapInfoHeader

        public BitmapInfoHeader getBitmapInfoHeader()

        Gets the bitmap information header.

        Value: The bitmap information header.
        Code example:

        The following example gets the information from the BMP header and prints it to the console.


        com.aspose.imaging.Image image = com.aspose.imaging.Image.load("c:\\temp\\sample.bmp");
        try {
            com.aspose.imaging.fileformats.bmp.BmpImage bmpImage = (com.aspose.imaging.fileformats.bmp.BmpImage) image;
            com.aspose.imaging.fileformats.bmp.BitmapInfoHeader header = bmpImage.getBitmapInfoHeader();
        
            System.out.println("The number of palette colors that are required for displaying the bitmap: " + header.getBitmapColorsImportant());
            System.out.println("The number of palette colors used in the bitmap: " + header.getBitmapColorsUsed());
            System.out.println("The bitmap compression: " + header.getBitmapCompression());
            System.out.println("The bitmap height: " + header.getBitmapHeight());
            System.out.println("The bitmap width: " + header.getBitmapWidth());
            System.out.println("The bitmap raw data size in bytes: " + header.getBitmapImageSize());
            System.out.println("The number of planes: " + header.getBitmapPlanes());
            System.out.println("The horizontal resolution of the bitmap, in pixels-per-meter: " + header.getBitmapXPelsPerMeter());
            System.out.println("The vertical resolution of the bitmap, in pixels-per-meter: " + header.getBitmapYPelsPerMeter());
            System.out.println("The number of bits per pixel: " + header.getBitsPerPixel());
            System.out.println("The extra bits masks: " + header.getExtraBitMasks());
            System.out.println("The header size in bytes: " + header.getHeaderSize());
        } finally {
            image.dispose();
        }
        
        //The output may look like this:
        //The number of palette colors that are required for displaying the bitmap: 0
        //The number of palette colors used in the bitmap: 0
        //The bitmap compression: 0
        //The bitmap height: 100
        //The bitmap width: 100
        //The bitmap raw data size in bytes: 40000
        //The number of planes: 1
        //The horizontal resolution of the bitmap, in pixels-per-meter: 0
        //The vertical resolution of the bitmap, in pixels-per-meter: 0
        //The number of bits per pixel: 32
        //The extra bits masks: null
        //The header size in bytes: 40
        

      • getFileFormat

        public long getFileFormat()

        Gets a value of file format

        Overrides:
        getFileFormat in class Image
        Code example:

        The following example shows how to extract information about raw data format and alpha channel from a BMP image.


        
        // The helper class used in the main example below.
        class Utils {
            // The helper method to get a string representation of the file format.
            public String getFileFormatString(long fileFormat) {
                if (fileFormat == com.aspose.imaging.FileFormat.Bmp) {
                    return "BMP";
                } else if (fileFormat == com.aspose.imaging.FileFormat.Gif) {
                    return "GIF";
                } else if (fileFormat == com.aspose.imaging.FileFormat.Dicom) {
                    return "DICOM";
                } else if (fileFormat == com.aspose.imaging.FileFormat.Djvu) {
                    return "DJVU";
                } else if (fileFormat == com.aspose.imaging.FileFormat.Dng) {
                    return "DNG";
                } else if (fileFormat == com.aspose.imaging.FileFormat.Png) {
                    return "PNG";
                } else if (fileFormat == com.aspose.imaging.FileFormat.Jpeg) {
                    return "JPEG";
                } else if (fileFormat == com.aspose.imaging.FileFormat.Jpeg2000) {
                    return "JPEG2000";
                } else if (fileFormat == com.aspose.imaging.FileFormat.Psd) {
                    return "PSD";
                } else if (fileFormat == com.aspose.imaging.FileFormat.Tiff) {
                    return "Tiff";
                } else if (fileFormat == com.aspose.imaging.FileFormat.Webp) {
                    return "WEBP";
                } else if (fileFormat == com.aspose.imaging.FileFormat.Cdr) {
                    return "CDR";
                } else if (fileFormat == com.aspose.imaging.FileFormat.Cmx) {
                    return "CMX";
                } else if (fileFormat == com.aspose.imaging.FileFormat.Emf) {
                    return "EMF";
                } else if (fileFormat == com.aspose.imaging.FileFormat.Wmf) {
                    return "WMF";
                } else if (fileFormat == com.aspose.imaging.FileFormat.Svg) {
                    return "SVG";
                } else if (fileFormat == com.aspose.imaging.FileFormat.Odg) {
                    return "ODG";
                } else if (fileFormat == com.aspose.imaging.FileFormat.Eps) {
                    return "EPS";
                } else {
                    return "UNDEFINED";
                }
            }
        }
        
        // Here is the main example
        Utils utils = new Utils();
        
        // Create a 32-bpp BMP image of 100 x 100 px.
        com.aspose.imaging.fileformats.bmp.BmpImage bmpImage = new com.aspose.imaging.fileformats.bmp.BmpImage(100, 100, 32, null);
        try {
            System.out.printf("FileFormat=%s, RawDataFormat=%s, HasAlpha=%s",
                    utils.getFileFormatString(bmpImage.getFileFormat()),
                    bmpImage.getRawDataFormat(),
                    bmpImage.hasAlpha());
            System.out.println();
        } finally {
            bmpImage.dispose();
        }
        
        // Create a 24-bpp BMP image of 100 x 100 px.
        bmpImage = new com.aspose.imaging.fileformats.bmp.BmpImage(100, 100, 24, null);
        try {
            System.out.printf("FileFormat=%s, RawDataFormat=%s, HasAlpha=%s",
                    utils.getFileFormatString(bmpImage.getFileFormat()),
                    bmpImage.getRawDataFormat(),
                    bmpImage.hasAlpha());
            System.out.println();
        } finally {
            bmpImage.dispose();
        }
        
        // In most cases BMP doesn't support alpha channel so the output will probably look like this:
        // FileFormat=BMP, RawDataFormat=Rgb32Bpp, used channels: 8,8,8,8, HasAlpha=false
        // FileFormat=BMP, RawDataFormat=Rgb24Bpp, used channels: 8,8,8, HasAlpha=false
        

      • getRawDataFormat

        public PixelDataFormat getRawDataFormat()

        Gets the raw data format.

        Value: The raw data format.
        Overrides:
        getRawDataFormat in class RasterImage
        Returns:
        The raw data format.
        Code example:

        The following example gets the general information about the image including pixel format, image size, resolution, compression etc.


        com.aspose.imaging.Image image = com.aspose.imaging.Image.load("c:\\temp\\sample.bmp");
        try {
            com.aspose.imaging.fileformats.bmp.BmpImage bmpImage = (com.aspose.imaging.fileformats.bmp.BmpImage) image;
        
            System.out.println("The pixel format: " + bmpImage.getRawDataFormat());
            System.out.println("The raw line size in bytes: " + bmpImage.getRawLineSize());
            System.out.println("The bitmap compression: " + bmpImage.getCompression());
            System.out.println("The bitmap width: " + bmpImage.getWidth());
            System.out.println("The bitmap height: " + bmpImage.getHeight());
            System.out.println("The number of bits per pixel: " + bmpImage.getBitsPerPixel());
        
            double hres = bmpImage.getHorizontalResolution();
            double vres = bmpImage.getVerticalResolution();
            System.out.println("The horizontal resolution, in pixels per inch: " + hres);
            System.out.println("The vertical resolution, in pixels per inch: " + vres);
        
            if (hres != 96.0 || vres != 96.0) {
                // You may consider using the SetResolution method for updating both resolution values in single call.
                System.out.println("Set resolution values to 96 dpi");
                bmpImage.setResolution(96.0, 96.0);
        
                System.out.println("The horizontal resolution, in pixels per inch: " + bmpImage.getHorizontalResolution());
                System.out.println("The vertical resolution, in pixels per inch: " + bmpImage.getVerticalResolution());
            }
        } finally {
            image.dispose();
        }
        
        //The output may look like this:
        //The pixel format: Rgb24Bpp, used channels: 8,8,8
        //The raw line size in bytes: 1500
        //The bitmap compression: 0
        //The bitmap width: 500
        //The bitmap height: 500
        //The number of bits per pixel: 24
        //The horizontal resolution, in pixels per inch: 96.012
        //The vertical resolution, in pixels per inch: 96.012
        //Set resolution values to 96 dpi
        //The horizontal resolution, in pixels per inch: 96.012
        //The vertical resolution, in pixels per inch: 96.012
        

      • getRawLineSize

        public int getRawLineSize()

        Gets the raw line size in bytes.

        Value: The raw line size in bytes.
        Overrides:
        getRawLineSize in class RasterImage
        Returns:
        The raw line size in bytes.
        Code example:

        The following example gets the general information about the image including pixel format, image size, resolution, compression etc.


        com.aspose.imaging.Image image = com.aspose.imaging.Image.load("c:\\temp\\sample.bmp");
        try {
            com.aspose.imaging.fileformats.bmp.BmpImage bmpImage = (com.aspose.imaging.fileformats.bmp.BmpImage) image;
        
            System.out.println("The pixel format: " + bmpImage.getRawDataFormat());
            System.out.println("The raw line size in bytes: " + bmpImage.getRawLineSize());
            System.out.println("The bitmap compression: " + bmpImage.getCompression());
            System.out.println("The bitmap width: " + bmpImage.getWidth());
            System.out.println("The bitmap height: " + bmpImage.getHeight());
            System.out.println("The number of bits per pixel: " + bmpImage.getBitsPerPixel());
        
            double hres = bmpImage.getHorizontalResolution();
            double vres = bmpImage.getVerticalResolution();
            System.out.println("The horizontal resolution, in pixels per inch: " + hres);
            System.out.println("The vertical resolution, in pixels per inch: " + vres);
        
            if (hres != 96.0 || vres != 96.0) {
                // You may consider using the SetResolution method for updating both resolution values in single call.
                System.out.println("Set resolution values to 96 dpi");
                bmpImage.setResolution(96.0, 96.0);
        
                System.out.println("The horizontal resolution, in pixels per inch: " + bmpImage.getHorizontalResolution());
                System.out.println("The vertical resolution, in pixels per inch: " + bmpImage.getVerticalResolution());
            }
        } finally {
            image.dispose();
        }
        
        //The output may look like this:
        //The pixel format: Rgb24Bpp, used channels: 8,8,8
        //The raw line size in bytes: 1500
        //The bitmap compression: 0
        //The bitmap width: 500
        //The bitmap height: 500
        //The number of bits per pixel: 24
        //The horizontal resolution, in pixels per inch: 96.012
        //The vertical resolution, in pixels per inch: 96.012
        //Set resolution values to 96 dpi
        //The horizontal resolution, in pixels per inch: 96.012
        //The vertical resolution, in pixels per inch: 96.012
        

      • getCompression

        public long getCompression()

        Gets the image compression.

        Value: The image compression.
        Code example:

        The following example shows how the bitmap compression affects the output image size.


        
        // The helper class used in the main example below.
        class Utils {
            // The helper method to get a string representation of the file format.
            public String getBitmapCompressionString(long bitmapCompression) {
                if (bitmapCompression == com.aspose.imaging.fileformats.bmp.BitmapCompression.Rgb) {
                    return "RGB";
                } else if (bitmapCompression == com.aspose.imaging.fileformats.bmp.BitmapCompression.Rle8) {
                    return "RLE8";
                } else if (bitmapCompression == com.aspose.imaging.fileformats.bmp.BitmapCompression.Rle4) {
                    return "RLE4";
                } else if (bitmapCompression == com.aspose.imaging.fileformats.bmp.BitmapCompression.Bitfields) {
                    return "BITFIELDS";
                } else if (bitmapCompression == com.aspose.imaging.fileformats.bmp.BitmapCompression.Jpeg) {
                    return "JPEG";
                } else if (bitmapCompression == com.aspose.imaging.fileformats.bmp.BitmapCompression.Png) {
                    return "PNG";
                } else if (bitmapCompression == com.aspose.imaging.fileformats.bmp.BitmapCompression.AlphaBitfields) {
                    return "ALPHA_BITFIELDS";
                } else {
                    return "UNDEFINED";
                }
            }
        }
        
        // Here is the main example
        Utils utils = new Utils();
        
        long[] compressions = new long[]
                {
                        com.aspose.imaging.fileformats.bmp.BitmapCompression.Rgb,
                        com.aspose.imaging.fileformats.bmp.BitmapCompression.Rle8,
                };
        
        com.aspose.imaging.Color[] paletterColors = new com.aspose.imaging.Color[]
                {
                        com.aspose.imaging.Color.getRed(),
                        com.aspose.imaging.Color.getGreen(),
                };
        
        // Create a monochrome palette which contains only red and green colors.
        com.aspose.imaging.IColorPalette palette = new com.aspose.imaging.ColorPalette(paletterColors);
        
        for (long compression : compressions) {
            // Create a 8-bpp BMP image of 100 x 100 px.
            com.aspose.imaging.fileformats.bmp.BmpImage bmpImage = new com.aspose.imaging.fileformats.bmp.BmpImage(100, 100, 8, palette, compression, 0.0, 0.0);
            try {
                com.aspose.imaging.Graphics gr = new com.aspose.imaging.Graphics(bmpImage);
        
                // Fill the entire image in red.
                com.aspose.imaging.brushes.SolidBrush redBrush = new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getRed());
                gr.fillRectangle(redBrush, bmpImage.getBounds());
        
                // Save the image to a stream to get the output image size.
                java.io.ByteArrayOutputStream stream = new java.io.ByteArrayOutputStream();
                try {
                    bmpImage.save(stream);
        
                    System.out.printf("---------------------------------------------\r\n");
                    System.out.printf("The compression=%s\r\n", utils.getBitmapCompressionString(bmpImage.getCompression()));
                    System.out.printf("The number of bits per pixel=%s\r\n", bmpImage.getBitsPerPixel());
                    System.out.printf("The image dimensions=%s x %s\r\n", bmpImage.getWidth(), bmpImage.getHeight());
                    System.out.printf("The raw line size=%s\r\n", bmpImage.getRawLineSize());
                    System.out.printf("The output size in bytes=%s\r\n", stream.size());
                } finally {
                    stream.close();
                }
            } finally {
                bmpImage.dispose();
            }
        }
        
        // The output may look like this:
        // The compression=RGB
        // The number of bits per pixel=8
        // The image dimensions=100 x 100
        // The raw line size=100
        // The output size in bytes=11078
        // ---------------------------------------------
        // The compression=RLE8
        // The number of bits per pixel=8
        // The image dimensions=100 x 100
        // The raw line size=100
        // The output size in bytes=856
        

      • getWidth

        public int getWidth()

        Gets the image width.

        Value: The image width.
        Specified by:
        getWidth in interface IObjectWithBounds
        Specified by:
        getWidth in class Image
        Returns:
        The image width.
        Code example:

        The following example gets the general information about the image including pixel format, image size, resolution, compression etc.


        com.aspose.imaging.Image image = com.aspose.imaging.Image.load("c:\\temp\\sample.bmp");
        try {
            com.aspose.imaging.fileformats.bmp.BmpImage bmpImage = (com.aspose.imaging.fileformats.bmp.BmpImage) image;
        
            System.out.println("The pixel format: " + bmpImage.getRawDataFormat());
            System.out.println("The raw line size in bytes: " + bmpImage.getRawLineSize());
            System.out.println("The bitmap compression: " + bmpImage.getCompression());
            System.out.println("The bitmap width: " + bmpImage.getWidth());
            System.out.println("The bitmap height: " + bmpImage.getHeight());
            System.out.println("The number of bits per pixel: " + bmpImage.getBitsPerPixel());
        
            double hres = bmpImage.getHorizontalResolution();
            double vres = bmpImage.getVerticalResolution();
            System.out.println("The horizontal resolution, in pixels per inch: " + hres);
            System.out.println("The vertical resolution, in pixels per inch: " + vres);
        
            if (hres != 96.0 || vres != 96.0) {
                // You may consider using the SetResolution method for updating both resolution values in single call.
                System.out.println("Set resolution values to 96 dpi");
                bmpImage.setResolution(96.0, 96.0);
        
                System.out.println("The horizontal resolution, in pixels per inch: " + bmpImage.getHorizontalResolution());
                System.out.println("The vertical resolution, in pixels per inch: " + bmpImage.getVerticalResolution());
            }
        } finally {
            image.dispose();
        }
        
        //The output may look like this:
        //The pixel format: Rgb24Bpp, used channels: 8,8,8
        //The raw line size in bytes: 1500
        //The bitmap compression: 0
        //The bitmap width: 500
        //The bitmap height: 500
        //The number of bits per pixel: 24
        //The horizontal resolution, in pixels per inch: 96.012
        //The vertical resolution, in pixels per inch: 96.012
        //Set resolution values to 96 dpi
        //The horizontal resolution, in pixels per inch: 96.012
        //The vertical resolution, in pixels per inch: 96.012
        

      • getHeight

        public int getHeight()

        Gets the image height.

        Value: The image height.
        Specified by:
        getHeight in interface IObjectWithBounds
        Specified by:
        getHeight in class Image
        Returns:
        The image height.
        Code example:

        The following example gets the general information about the image including pixel format, image size, resolution, compression etc.


        com.aspose.imaging.Image image = com.aspose.imaging.Image.load("c:\\temp\\sample.bmp");
        try {
            com.aspose.imaging.fileformats.bmp.BmpImage bmpImage = (com.aspose.imaging.fileformats.bmp.BmpImage) image;
        
            System.out.println("The pixel format: " + bmpImage.getRawDataFormat());
            System.out.println("The raw line size in bytes: " + bmpImage.getRawLineSize());
            System.out.println("The bitmap compression: " + bmpImage.getCompression());
            System.out.println("The bitmap width: " + bmpImage.getWidth());
            System.out.println("The bitmap height: " + bmpImage.getHeight());
            System.out.println("The number of bits per pixel: " + bmpImage.getBitsPerPixel());
        
            double hres = bmpImage.getHorizontalResolution();
            double vres = bmpImage.getVerticalResolution();
            System.out.println("The horizontal resolution, in pixels per inch: " + hres);
            System.out.println("The vertical resolution, in pixels per inch: " + vres);
        
            if (hres != 96.0 || vres != 96.0) {
                // You may consider using the SetResolution method for updating both resolution values in single call.
                System.out.println("Set resolution values to 96 dpi");
                bmpImage.setResolution(96.0, 96.0);
        
                System.out.println("The horizontal resolution, in pixels per inch: " + bmpImage.getHorizontalResolution());
                System.out.println("The vertical resolution, in pixels per inch: " + bmpImage.getVerticalResolution());
            }
        } finally {
            image.dispose();
        }
        
        //The output may look like this:
        //The pixel format: Rgb24Bpp, used channels: 8,8,8
        //The raw line size in bytes: 1500
        //The bitmap compression: 0
        //The bitmap width: 500
        //The bitmap height: 500
        //The number of bits per pixel: 24
        //The horizontal resolution, in pixels per inch: 96.012
        //The vertical resolution, in pixels per inch: 96.012
        //Set resolution values to 96 dpi
        //The horizontal resolution, in pixels per inch: 96.012
        //The vertical resolution, in pixels per inch: 96.012
        

      • getBitsPerPixel

        public int getBitsPerPixel()

        Gets the image bits per pixel count.

        Value: The image bits per pixel count.
        Specified by:
        getBitsPerPixel in class Image
        Returns:
        The image bits per pixel count.
        Code example:

        The following example gets the general information about the image including pixel format, image size, resolution, compression etc.


        com.aspose.imaging.Image image = com.aspose.imaging.Image.load("c:\\temp\\sample.bmp");
        try {
            com.aspose.imaging.fileformats.bmp.BmpImage bmpImage = (com.aspose.imaging.fileformats.bmp.BmpImage) image;
        
            System.out.println("The pixel format: " + bmpImage.getRawDataFormat());
            System.out.println("The raw line size in bytes: " + bmpImage.getRawLineSize());
            System.out.println("The bitmap compression: " + bmpImage.getCompression());
            System.out.println("The bitmap width: " + bmpImage.getWidth());
            System.out.println("The bitmap height: " + bmpImage.getHeight());
            System.out.println("The number of bits per pixel: " + bmpImage.getBitsPerPixel());
        
            double hres = bmpImage.getHorizontalResolution();
            double vres = bmpImage.getVerticalResolution();
            System.out.println("The horizontal resolution, in pixels per inch: " + hres);
            System.out.println("The vertical resolution, in pixels per inch: " + vres);
        
            if (hres != 96.0 || vres != 96.0) {
                // You may consider using the SetResolution method for updating both resolution values in single call.
                System.out.println("Set resolution values to 96 dpi");
                bmpImage.setResolution(96.0, 96.0);
        
                System.out.println("The horizontal resolution, in pixels per inch: " + bmpImage.getHorizontalResolution());
                System.out.println("The vertical resolution, in pixels per inch: " + bmpImage.getVerticalResolution());
            }
        } finally {
            image.dispose();
        }
        
        //The output may look like this:
        //The pixel format: Rgb24Bpp, used channels: 8,8,8
        //The raw line size in bytes: 1500
        //The bitmap compression: 0
        //The bitmap width: 500
        //The bitmap height: 500
        //The number of bits per pixel: 24
        //The horizontal resolution, in pixels per inch: 96.012
        //The vertical resolution, in pixels per inch: 96.012
        //Set resolution values to 96 dpi
        //The horizontal resolution, in pixels per inch: 96.012
        //The vertical resolution, in pixels per inch: 96.012
        

      • getHorizontalResolution

        public double getHorizontalResolution()

        Gets or sets the horizontal resolution, in pixels per inch, of this RasterImage.

        Value: The horizontal resolution.

        Note by default this value is always 96 since different platforms cannot return the screen resolution. You may consider using the SetResolution method for updating both resolution values in single call.

        Overrides:
        getHorizontalResolution in class RasterImage
        Returns:
        The horizontal resolution.

        Note by default this value is always 96 since different platforms cannot return the screen resolution. You may consider using the SetResolution method for updating both resolution values in single call.

        Code example:

        The following example shows how to set horizontal/vertical resolution of a BMP image.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.bmp");
        try {
            com.aspose.imaging.fileformats.bmp.BmpImage bmpImage = (com.aspose.imaging.fileformats.bmp.BmpImage) image;
        
            // Get horizontal and vertical resolution of the BmpImage
            double horizontalResolution = bmpImage.getHorizontalResolution();
            double verticalResolution = bmpImage.getVerticalResolution();
            System.out.println("The horizontal resolution, in pixels per inch: " + horizontalResolution);
            System.out.println("The vertical resolution, in pixels per inch: " + verticalResolution);
        
            if (horizontalResolution != 96.0 || verticalResolution != 96.0) {
                // Use the SetResolution method for updating both resolution values in a single call.
                System.out.println("Set resolution values to 96 dpi");
                bmpImage.setResolution(96.0, 96.0);
        
                System.out.println("The horizontal resolution, in pixels per inch: " + bmpImage.getHorizontalResolution());
                System.out.println("The vertical resolution, in pixels per inch: " + bmpImage.getVerticalResolution());
            }
        } finally {
            image.dispose();
        }
        
        // The output may look like this:
        // The horizontal resolution, in pixels per inch: 0.0
        // The vertical resolution, in pixels per inch: 0.0
        // Set resolution values to 96 dpi
        // The horizontal resolution, in pixels per inch: 96.012
        // The vertical resolution, in pixels per inch: 96.012
        

      • setHorizontalResolution

        public void setHorizontalResolution(double value)

        Gets or sets the horizontal resolution, in pixels per inch, of this RasterImage.

        Value: The horizontal resolution.

        Note by default this value is always 96 since different platforms cannot return the screen resolution. You may consider using the SetResolution method for updating both resolution values in single call.

        Overrides:
        setHorizontalResolution in class RasterImage
        Parameters:
        value - The horizontal resolution.

        Note by default this value is always 96 since different platforms cannot return the screen resolution. You may consider using the SetResolution method for updating both resolution values in single call.

      • getVerticalResolution

        public double getVerticalResolution()

        Gets or sets the vertical resolution, in pixels per inch, of this RasterImage.

        Value: The vertical resolution.

        Note by default this value is always 96 since different platforms cannot return the screen resolution. You may consider using the SetResolution method for updating both resolution values in single call.

        Overrides:
        getVerticalResolution in class RasterImage
        Returns:
        The vertical resolution.

        Note by default this value is always 96 since different platforms cannot return the screen resolution. You may consider using the SetResolution method for updating both resolution values in single call.

        Code example:

        The following example shows how to set horizontal/vertical resolution of a BMP image.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.bmp");
        try {
            com.aspose.imaging.fileformats.bmp.BmpImage bmpImage = (com.aspose.imaging.fileformats.bmp.BmpImage) image;
        
            // Get horizontal and vertical resolution of the BmpImage
            double horizontalResolution = bmpImage.getHorizontalResolution();
            double verticalResolution = bmpImage.getVerticalResolution();
            System.out.println("The horizontal resolution, in pixels per inch: " + horizontalResolution);
            System.out.println("The vertical resolution, in pixels per inch: " + verticalResolution);
        
            if (horizontalResolution != 96.0 || verticalResolution != 96.0) {
                // Use the SetResolution method for updating both resolution values in a single call.
                System.out.println("Set resolution values to 96 dpi");
                bmpImage.setResolution(96.0, 96.0);
        
                System.out.println("The horizontal resolution, in pixels per inch: " + bmpImage.getHorizontalResolution());
                System.out.println("The vertical resolution, in pixels per inch: " + bmpImage.getVerticalResolution());
            }
        } finally {
            image.dispose();
        }
        
        // The output may look like this:
        // The horizontal resolution, in pixels per inch: 0.0
        // The vertical resolution, in pixels per inch: 0.0
        // Set resolution values to 96 dpi
        // The horizontal resolution, in pixels per inch: 96.012
        // The vertical resolution, in pixels per inch: 96.012
        

      • setVerticalResolution

        public void setVerticalResolution(double value)

        Gets or sets the vertical resolution, in pixels per inch, of this RasterImage.

        Value: The vertical resolution.

        Note by default this value is always 96 since different platforms cannot return the screen resolution. You may consider using the SetResolution method for updating both resolution values in single call.

        Overrides:
        setVerticalResolution in class RasterImage
        Parameters:
        value - The vertical resolution.

        Note by default this value is always 96 since different platforms cannot return the screen resolution. You may consider using the SetResolution method for updating both resolution values in single call.

      • setResolution

        public void setResolution(double dpiX,
                                  double dpiY)

        Sets the resolution for this RasterImage.

        Overrides:
        setResolution in class RasterImage
        Parameters:
        dpiX - The horizontal resolution, in dots per inch, of the RasterImage.
        dpiY - The vertical resolution, in dots per inch, of the RasterImage.
        Code example:

        The following example shows how to set horizontal/vertical resolution of a BMP image.


        String dir = "c:\\temp\\";
        
        com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.bmp");
        try {
            com.aspose.imaging.fileformats.bmp.BmpImage bmpImage = (com.aspose.imaging.fileformats.bmp.BmpImage) image;
        
            // Get horizontal and vertical resolution of the BmpImage
            double horizontalResolution = bmpImage.getHorizontalResolution();
            double verticalResolution = bmpImage.getVerticalResolution();
            System.out.println("The horizontal resolution, in pixels per inch: " + horizontalResolution);
            System.out.println("The vertical resolution, in pixels per inch: " + verticalResolution);
        
            if (horizontalResolution != 96.0 || verticalResolution != 96.0) {
                // Use the SetResolution method for updating both resolution values in a single call.
                System.out.println("Set resolution values to 96 dpi");
                bmpImage.setResolution(96.0, 96.0);
        
                System.out.println("The horizontal resolution, in pixels per inch: " + bmpImage.getHorizontalResolution());
                System.out.println("The vertical resolution, in pixels per inch: " + bmpImage.getVerticalResolution());
            }
        } finally {
            image.dispose();
        }
        
        // The output may look like this:
        // The horizontal resolution, in pixels per inch: 0.0
        // The vertical resolution, in pixels per inch: 0.0
        // Set resolution values to 96 dpi
        // The horizontal resolution, in pixels per inch: 96.012
        // The vertical resolution, in pixels per inch: 96.012