public final class BmpImage extends RasterCachedImage
You can effortlessly handle Bitmap (BMP) and Device Independent Bitmap (DIB) files, facilitating efficient manipulation and processing of raster images. Performing various operations on images, this API streamlines the workflow, offering developers a reliable toolkit for working with BMP and DIB formats in their software applications.
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 and Description |
|---|
BmpImage(InputStream stream)
Begin using the
BmpImage class effortlessly by initializing a new instance
with this constructor, using a stream as input. |
BmpImage(InputStream stream,
int bitsPerPixel,
long compression,
double horizontalResolution,
double verticalResolution)
Start working with the
BmpImage class seamlessly by creating
a new instance using a stream, along with specified parameters like bitsPerPixel
and compression. |
BmpImage(int width,
int height)
Start using the
BmpImage class effortlessly by creating a new instance
with specified width and height parameters. |
BmpImage(int width,
int height,
int bitsPerPixel,
IColorPalette palette)
Begin using the
BmpImage class seamlessly by initializing a new instance
with parameters such as width, height, bit-depth, and palette. |
BmpImage(int width,
int height,
int bitsPerPixel,
IColorPalette palette,
long compression,
double horizontalResolution,
double verticalResolution)
Effortlessly create a new instance of the
BmpImage class with this constructor,
specifying parameters like width, height, bitsPerPixel, and palette. |
BmpImage(RasterImage rasterImage)
Effortlessly create a new instance of the
BmpImage class
by initializing it with a RasterImage object. |
BmpImage(RasterImage rasterImage,
int bitsPerPixel,
long compression,
double horizontalResolution,
double verticalResolution)
Start working with the
BmpImage class seamlessly by creating a new instance
using a rasterImage along with specified parameters like bitsPerPixel and compression. |
BmpImage(String path)
Start using the BmpImage class effortlessly with this constructor that
initializes a new instance.
|
BmpImage(String path,
int bitsPerPixel,
long compression,
double horizontalResolution,
double verticalResolution)
Effortlessly create a new instance of the
BmpImage class with this constructor,
using specified parameters like path, bitsPerPixel, and compression. |
| Modifier and Type | Method and Description |
|---|---|
BitmapInfoHeader |
getBitmapInfoHeader()
Quickly access essential details about your bitmap image with this straightforward function.
|
int |
getBitsPerPixel()
Access the number of bits per pixel for the image with ease using this property.
|
long |
getCompression()
Retrieve the compression type used for the image effortlessly with this property.
|
ImageOptionsBase |
getDefaultOptions(Object[] args)
Retrieve the default options effortlessly with this straightforward method.
|
long |
getFileFormat()
Easily retrieve the file format value with this user-friendly property.
|
int |
getHeight()
Retrieve the height of the image effortlessly with this property.
|
double |
getHorizontalResolution()
This property allows you to easily get or set the horizontal resolution,
measured in pixels per inch, of the
RasterImage object. |
PixelDataFormat |
getRawDataFormat()
Easily obtain the format of your raw data with this user-friendly function.
|
int |
getRawLineSize()
Quickly access the size of each raw line in bytes with this straightforward property.
|
double |
getVerticalResolution()
Easily retrieve or set the vertical resolution, measured in pixels per inch,
of this
RasterImage object with this property. |
int |
getWidth()
Access the width of the image easily with this property.
|
boolean |
hasAlpha()
Gets a value indicating whether this instance has alpha.
|
void |
setHorizontalResolution(double value)
This property allows you to easily get or set the horizontal resolution,
measured in pixels per inch, of the
RasterImage object. |
void |
setResolution(double dpiX,
double dpiY)
Adjust the resolution of your
RasterImage effortlessly with this
user-friendly method. |
void |
setVerticalResolution(double value)
Easily retrieve or set the vertical resolution, measured in pixels per inch,
of this
RasterImage object with this property. |
adjustBrightness, adjustContrast, adjustGamma, adjustGamma, analyzePercentageDigitalSignature, autoBrightnessContrast, binarizeBradley, binarizeBradley, binarizeFixed, binarizeOtsu, blend, cacheData, crop, dither, embedDigitalSignature, grayscale, isCached, isDigitalSigned, normalizeHistogram, resize, resize, rotate, rotateFlipblend, blend, blend, dither, filter, getArgb32Pixel, getDefaultArgb32Pixels, getDefaultPixels, getDefaultRawData, getDefaultRawData, getImageOpacity, getModifyDate, getPixel, getPremultiplyComponents, getRawCustomColorConverter, getRawDataSettings, getRawFallbackIndex, getRawIndexedColorConverter, getSkewAngle, getTransparentColor, getUpdateXmpData, getUseRawData, getXmpData, hasTransparentColor, isDigitalSigned, isRawDataAvailable, isUsePalette, loadArgb32Pixels, loadArgb64Pixels, loadCmyk32Pixels, loadCmykPixels, loadPartialArgb32Pixels, loadPartialArgb64Pixels, loadPartialPixels, loadPixels, loadRawData, loadRawData, normalizeAngle, normalizeAngle, readArgb32ScanLine, readScanLine, removeMetadata, replaceColor, replaceColor, replaceNonTransparentColors, replaceNonTransparentColors, rotate, saveArgb32Pixels, saveCmyk32Pixels, saveCmykPixels, savePixels, saveRawData, setArgb32Pixel, setPalette, setPixel, setPremultiplyComponents, setRawCustomColorConverter, setRawFallbackIndex, setRawIndexedColorConverter, setTransparentColor, setTransparentColor, setUpdateXmpData, setUseRawData, setXmpData, toBitmap, writeArgb32ScanLine, writeScanLinecanLoad, canLoad, canLoad, canLoad, canSave, create, create, create, create, create, create, crop, getBackgroundColor, getBounds, getBufferSizeHint, getContainer, getFileFormat, getFileFormat, getFittingRectangle, getFittingRectangle, getInterruptMonitor, getIProgressEventHandler, getOriginalOptions, getPalette, getProgressEventHandlerInfo, getProportionalHeight, getProportionalWidth, getSerializedStream, getSize, hasBackgroundColor, isAutoAdjustPalette, load, load, load, load, load, load, resize, resizeHeightProportionally, resizeHeightProportionally, resizeHeightProportionally, resizeWidthProportionally, resizeWidthProportionally, resizeWidthProportionally, save, save, save, save, save, save, save, save, setAutoAdjustPalette, setBackgroundColor, setBackgroundColor, setBufferSizeHint, setInterruptMonitor, setPalettegetDataStreamContainer, save, save, saveclose, dispose, getDisposedpublic BmpImage(String path)
Start using the BmpImage class effortlessly with this constructor that
initializes a new instance. Perfect for developers who want to get up and
running with BmpImage objects quickly and efficiently.
path - The path to load image from and initialize pixel and palette data with.com.aspose.ms.System.ArgumentNullException - The raster image is null.BmpImageException - The height must be positive.com.aspose.ms.System.ArgumentException - Palette must be specified for images with 8 bits per pixel or less.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();
}
public BmpImage(String path, int bitsPerPixel, long compression, double horizontalResolution, double verticalResolution)
Effortlessly create a new instance of the BmpImage class with this constructor,
using specified parameters like path, bitsPerPixel, and compression. Ideal for developers
looking to initialize BmpImage objects quickly and efficiently, with precise control
over image characteristics.
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.com.aspose.ms.System.ArgumentNullException - The raster image is null.BmpImageException - The height must be positive.com.aspose.ms.System.ArgumentException - Palette must be specified for images with 8 bits per pixel or less.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();
}
public BmpImage(InputStream stream)
Begin using the BmpImage class effortlessly by initializing a new instance
with this constructor, using a stream as input. Perfect for developers seeking
a convenient way to work with BmpImage objects from various data sources,
ensuring flexibility and ease of integration.
stream - The stream to load image from and initialize pixel and palette data with.com.aspose.ms.System.ArgumentNullException - The raster image is null.BmpImageException - The height must be positive.com.aspose.ms.System.ArgumentException - Palette must be specified for images with 8 bits per pixel or less.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();
}
public BmpImage(InputStream stream, int bitsPerPixel, long compression, double horizontalResolution, double verticalResolution)
Start working with the BmpImage class seamlessly by creating
a new instance using a stream, along with specified parameters like bitsPerPixel
and compression. Perfect for developers seeking a straightforward way to handle
BmpImage objects, ensuring flexibility and efficiency in their projects.
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.com.aspose.ms.System.ArgumentNullException - The raster image is null.BmpImageException - The height must be positive.com.aspose.ms.System.ArgumentException - Palette must be specified for images with 8 bits per pixel or less.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();
}
public BmpImage(RasterImage rasterImage)
Effortlessly create a new instance of the BmpImage class
by initializing it with a RasterImage object. Perfect for developers looking
to seamlessly convert existing raster images to the BmpImage format, ensuring
compatibility and ease of integration into their projects.
rasterImage - The image to initialize pixel and palette data with.com.aspose.ms.System.ArgumentNullException - The raster image is null.BmpImageException - The height must be positive.com.aspose.ms.System.ArgumentException - Palette must be specified for images with 8 bits per pixel or less.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();
}
public BmpImage(RasterImage rasterImage, int bitsPerPixel, long compression, double horizontalResolution, double verticalResolution)
Start working with the BmpImage class seamlessly by creating a new instance
using a rasterImage along with specified parameters like bitsPerPixel and compression.
Perfect for developers seeking a straightforward way to handle BmpImage objects,
ensuring flexibility and efficiency in their projects.
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.com.aspose.ms.System.ArgumentNullException - The raster image is null.BmpImageException - The height must be positive.com.aspose.ms.System.ArgumentException - Palette must be specified for images with 8 bits per pixel or less.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();
}
public BmpImage(int width,
int height)
Start using the BmpImage class effortlessly by creating a new instance
with specified width and height parameters. Ideal for developers seeking
a convenient way to generate BmpImage objects of custom dimensions, ensuring
flexibility and ease of integration into their projects.
width - The image width.height - The image height.BmpImageException - The height must be positive.com.aspose.ms.System.ArgumentException - Palette must be specified for images with 8 bits per pixel or less.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();
}
public BmpImage(int width,
int height,
int bitsPerPixel,
IColorPalette palette)
Begin using the BmpImage class seamlessly by initializing a new instance
with parameters such as width, height, bit-depth, and palette. Perfect for
developers seeking a straightforward way to create BmpImage objects with
custom dimensions and color configurations, ensuring flexibility and efficiency in their projects.
width - The image width.height - The image height.bitsPerPixel - The bits per pixel.palette - The color palette.BmpImageException - The height must be positive.com.aspose.ms.System.ArgumentException - Palette must be specified for images with 8 bits per pixel or less.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();
}
public BmpImage(int width,
int height,
int bitsPerPixel,
IColorPalette palette,
long compression,
double horizontalResolution,
double verticalResolution)
Effortlessly create a new instance of the BmpImage class with this constructor,
specifying parameters like width, height, bitsPerPixel, and palette. Perfect for developers
seeking a convenient way to generate BmpImage objects with custom dimensions
and color configurations, ensuring flexibility and ease of integration into their projects.
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.BmpImageException - The height must be positive.com.aspose.ms.System.ArgumentException - Palette must be specified for images with 8 bits per pixel or less.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();
}
public BitmapInfoHeader getBitmapInfoHeader()
Quickly access essential details about your bitmap image with this straightforward function. Perfect for developers needing to retrieve header information for their images.
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
public long getFileFormat()
Easily retrieve the file format value with this user-friendly property. Ideal for developers seeking quick access to information about the file format.
getFileFormat in class ImageFileFormatThe 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
public PixelDataFormat getRawDataFormat()
Easily obtain the format of your raw data with this user-friendly function. Perfect for developers looking to quickly access crucial information about their data format.
getRawDataFormat in class RasterImagePixelDataFormatThe 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
public int getRawLineSize()
Quickly access the size of each raw line in bytes with this straightforward property. Ideal for developers needing to efficiently handle raw image data.
getRawLineSize in class RasterImageThe 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
public long getCompression()
Retrieve the compression type used for the image effortlessly with this property. Perfect for developers needing to quickly access information about image compression.
BitmapCompression.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
public int getWidth()
Access the width of the image easily with this property. Ideal for developers seeking quick information about the image dimensions.
getWidth in interface IObjectWithBoundsgetWidth in class ImageThe 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
public int getHeight()
Retrieve the height of the image effortlessly with this property. Ideal for developers needing quick access to information about image dimensions.
getHeight in interface IObjectWithBoundsgetHeight in class ImageThe 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
public int getBitsPerPixel()
Access the number of bits per pixel for the image with ease using this property. Perfect for developers seeking quick information about image quality and depth.
getBitsPerPixel in class ImageThe 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
public double getHorizontalResolution()
This property allows you to easily get or set the horizontal resolution,
measured in pixels per inch, of the RasterImage object. Ideal for
developers needing precise control over image resolution for their applications.
getHorizontalResolution in class RasterImageNote by default this value is always 96 since different platforms cannot return the screen resolution.
You may consider using the BmpImage.setResolution(double, double) method for updating both resolution values in single call.
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
public void setHorizontalResolution(double value)
This property allows you to easily get or set the horizontal resolution,
measured in pixels per inch, of the RasterImage object. Ideal for
developers needing precise control over image resolution for their applications.
setHorizontalResolution in class RasterImagevalue - The horizontal resolution.Note by default this value is always 96 since different platforms
cannot return the screen resolution.
You may consider using the BmpImage.setResolution(double, double) method for updating both resolution values in single call.
public double getVerticalResolution()
Easily retrieve or set the vertical resolution, measured in pixels per inch,
of this RasterImage object with this property. Perfect for developers requiring
precise control over image resolution in their applications.
getVerticalResolution in class RasterImageNote by default this value is always 96 since different platforms cannot
return the screen resolution. You may consider using the BmpImage.setResolution(double, double) method for
updating both resolution values in single call.
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
public void setVerticalResolution(double value)
Easily retrieve or set the vertical resolution, measured in pixels per inch,
of this RasterImage object with this property. Perfect for developers requiring
precise control over image resolution in their applications.
setVerticalResolution in class RasterImagevalue - The vertical resolution.Note by default this value is always 96 since different platforms cannot
return the screen resolution. You may consider using the BmpImage.setResolution(double, double) method for
updating both resolution values in single call.
public boolean hasAlpha()
Gets a value indicating whether this instance has alpha.
hasAlpha in class RasterImagepublic void setResolution(double dpiX,
double dpiY)
Adjust the resolution of your RasterImage effortlessly with this
user-friendly method. Perfect for developers seeking precise control over
image resolution in their applications.
setResolution in class RasterImagedpiX - The horizontal resolution, in dots per inch, of the RasterImage.dpiY - The vertical resolution, in dots per inch, of the RasterImage.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
public ImageOptionsBase getDefaultOptions(Object[] args)
Retrieve the default options effortlessly with this straightforward method. Ideal for developers seeking quick access to default image settings or configurations.
getDefaultOptions in class Imageargs - The arguments.Copyright (c) 2008-2025 Aspose Pty Ltd. All Rights Reserved.