BmpImage Class

Summary: 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.

Module: aspose.imaging.fileformats.bmp

Full Name: aspose.imaging.fileformats.bmp.BmpImage

Inheritance: IObjectWithBounds, IRasterImageArgb32PixelLoader, IRasterImageRawDataLoader, IHasXmpData, IHasMetadata, RasterCachedImage

Aspose.Imaging Version: 24.7.0

Constructors

NameDescription
BmpImage(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.
BmpImage(path, bits_per_pixel, compression, horizontal_resolution, vertical_resolution)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.
BmpImage(raster_image)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.
BmpImage(raster_image, bits_per_pixel, compression, horizontal_resolution, vertical_resolution)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.
BmpImage(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.
BmpImage(stream, bits_per_pixel, compression, horizontal_resolution, vertical_resolution)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.
BmpImage(width, 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.
BmpImage(width, height, bits_per_pixel, 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.
BmpImage(width, height, bits_per_pixel, palette, compression, horizontal_resolution, vertical_resolution)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.

Properties

NameTypeAccessDescription
auto_adjust_paletteboolr/wGets or sets a value indicating whether automatic adjust palette.
background_colorColorr/wGets or sets a value for the background color.
bitmap_info_headerBitmapInfoHeaderrQuickly access essential details about your bitmap image with this straightforward function.
Perfect for developers needing to retrieve header information for their images.
bits_per_pixelintrAccess 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.
boundsRectanglerGets the object bounds.
buffer_size_hintintr/wGets or sets the buffer size hint which is defined max allowed size for all internal buffers.
compressionBitmapCompressionrRetrieve the compression type used for the image effortlessly with this property.
Perfect for developers needing to quickly access information about image compression.
containerImagerGets the Image container.
data_stream_containerStreamContainerrGets the object’s data stream.
disposedboolrGets a value indicating whether this instance is disposed.
file_formatFileFormatrEasily retrieve the file format value with this user-friendly property.
Ideal for developers seeking quick access to information about the file format.
has_alphaboolrGets a value indicating whether this instance has alpha.
has_background_colorboolr/wGets or sets a value indicating whether image has background color.
has_transparent_colorboolr/wGets a value indicating whether image has transparent color.
heightintrRetrieve the height of the image effortlessly with this property. Ideal for developers
needing quick access to information about image dimensions.
horizontal_resolutiondoubler/wThis 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.
image_opacityfloatrGets opacity of this image.
interrupt_monitorInterruptMonitorr/wGets or sets the interrupt monitor.
is_cachedboolrGets a value indicating whether image data is cached currently.
is_raw_data_availableboolrGets a value indicating whether raw data loading is supported.
paletteIColorPaletter/wGets or sets the color palette. The color palette is not used when pixels are represented directly.
premultiply_componentsboolr/wGets or sets a value indicating whether the image components must be premultiplied.
raw_custom_color_converterIColorConverterr/wGets or sets the custom color converter
raw_data_formatPixelDataFormatrEasily 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.
raw_data_settingsRawDataSettingsrGets the current raw data settings. Note when using these settings the data loads without conversion.
raw_fallback_indexintr/wGets or sets the fallback index to use when palette index is out of bounds
raw_indexed_color_converterIIndexedColorConverterr/wGets or sets the indexed color converter
raw_line_sizeintrQuickly access the size of each raw line in bytes with this straightforward property.
Ideal for developers needing to efficiently handle raw image data.
sizeSizerGets the object size.
transparent_colorColorr/wGets the image transparent color.
update_xmp_databoolr/wGets or sets a value indicating whether to update the XMP metadata.
use_paletteboolrGets a value indicating whether the image palette is used.
use_raw_databoolr/wGets or sets a value indicating whether to use raw data loading when the raw data loading is available.
vertical_resolutiondoubler/wEasily 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.
widthintrAccess the width of the image easily with this property. Ideal for developers
seeking quick information about the image dimensions.
xmp_dataXmpPacketWrapperr/wGets or sets Xmp data.

Methods

NameDescription
adjust_brightness(brightness)Adjust of a brightness for image.
adjust_contrast(contrast)Image contrasting
adjust_gamma(gamma)Gamma-correction of an image.
adjust_gamma(gamma_red, gamma_green, gamma_blue)Gamma-correction of an image.
binarize_bradley(brightness_difference)Binarization of an image using Bradley’s adaptive thresholding algorithm using the integral image thresholding
binarize_bradley(brightness_difference, window_size)Binarization of an image using Bradley’s adaptive thresholding algorithm using the integral image thresholding
binarize_fixed(threshold)Binarization of an image with predefined threshold
binarize_otsu()Binarization of an image with Otsu thresholding
blend(origin, overlay, overlay_alpha)Blends this image instance with the overlay image.
blend(origin, overlay, overlay_area, overlay_alpha)Blends this image instance with the overlay image.
cache_data()Caches the data and ensures no additional data loading will be performed from the underlying DataStreamSupporter.data_stream_container.
can_load(file_path)Determines whether image can be loaded from the specified file path.
can_load(file_path, load_options)Determines whether image can be loaded from the specified file path and optionally using the specified open options.
can_load(stream)Determines whether image can be loaded from the specified stream.
can_load(stream, load_options)Determines whether image can be loaded from the specified stream and optionally using the specified loadOptions.
can_load_stream(stream)Determines whether image can be loaded from the specified stream.
can_load_stream_with_options(stream, load_options)Determines whether image can be loaded from the specified stream and optionally using the specified loadOptions.
can_load_with_options(file_path, load_options)Determines whether image can be loaded from the specified file path and optionally using the specified open options.
can_save(options)Determines whether image can be saved to the specified file format represented by the passed save options.
create(image_options, width, height)Creates a new image using the specified create options.
create(images)Creates a new image using the specified images as pages
create(images, dispose_images)Creates a new image the specified images as pages.
create_from_file_with_params(path, bits_per_pixel, compression, horizontal_resolution, vertical_resolution)Easily begin using the BmpImage class with this constructor, simplifying
the process of initializing a new instance. Ideal for developers seeking
a quick and efficient way to incorporate BmpImage objects into their projects.
create_from_image(raster_image)Initializes a new instance of the BmpImage class.
create_from_image_with_params(raster_image, bits_per_pixel, compression, horizontal_resolution, vertical_resolution)Initializes a new instance of the BmpImage class.
create_from_stream(stream)Initializes a new instance of the BmpImage class.
create_from_stream_with_params(stream, bits_per_pixel, compression, horizontal_resolution, vertical_resolution)Initializes a new instance of the BmpImage class.
crop(left_shift, right_shift, top_shift, bottom_shift)Crop image with shifts.
crop(rectangle)Cropping the image.
dither(dithering_method, bits_count)Performs dithering on the current image.
dither(dithering_method, bits_count, custom_palette)Performs dithering on the current image.
filter(rectangle, options)Filters the specified rectangle.
get_argb_32_pixel(x, y)Gets an image 32-bit ARGB pixel.
get_default_argb_32_pixels(rectangle)Gets the default 32-bit ARGB pixels array.
get_default_options(args)Retrieve the default options effortlessly with this straightforward method.
Ideal for developers seeking quick access to default image settings or configurations.
get_default_pixels(rectangle, partial_pixel_loader)Gets the default pixels array using partial pixel loader.
get_default_raw_data(rectangle, partial_raw_data_loader, raw_data_settings)Gets the default raw data array using partial pixel loader.
get_default_raw_data(rectangle, raw_data_settings)Gets the default raw data array.
get_file_format(file_path)Gets the file format.
get_file_format(stream)Gets the file format.
get_file_format_of_stream(stream)Gets the file format.
get_fitting_rectangle(rectangle, pixels, width, height)Gets rectangle which fits the current image.
get_fitting_rectangle(rectangle, width, height)Gets rectangle which fits the current image.
get_modify_date(use_default)Gets the date and time the resource image was last modified.
get_original_options()Gets the options based on the original file settings.
This can be helpful to keep bit-depth and other parameters of the original image unchanged.
For example, if we load a black-white PNG image with 1 bit per pixel and then save it using the
DataStreamSupporter.save(file_path) method, the output PNG image with 8-bit per pixel will be produced.
To avoid it and save PNG image with 1-bit per pixel, use this method to get corresponding saving options and pass them
to the Image.save(file_path, options) method as the second parameter.
get_pixel(x, y)Gets an image pixel.
get_proportional_height(width, height, new_width)Gets a proportional height.
get_proportional_width(width, height, new_height)Gets a proportional width.
get_serialized_stream(image_options, clipping_rectangle, page_number)Converts to aps.
get_skew_angle()Gets the skew angle.
This method is applicable to scanned text documents, to determine the skew angle when scanning.
grayscale()Transformation of an image to its grayscale representation
load(file_path)Loads a new image from the specified file.
load(file_path, load_options)Loads a new image from the specified file.
load(stream)Loads a new image from the specified stream.
load(stream, load_options)Loads a new image from the specified stream.
load_argb_32_pixels(rectangle)Loads 32-bit ARGB pixels.
load_argb_64_pixels(rectangle)Loads 64-bit ARGB pixels.
load_cmyk_32_pixels(rectangle)Loads pixels in CMYK format.
load_cmyk_pixels(rectangle)Loads pixels in CMYK format.
This method is deprecated. Please use more effective the RasterImage.load_cmyk_32_pixels(rectangle) method.
load_partial_argb_32_pixels(rectangle, partial_pixel_loader)Loads 32-bit ARGB pixels partially (by blocks).
load_partial_argb_64_pixels(rectangle, partial_pixel_loader)Loads 64-bit ARGB pixels partially by packs.
load_partial_pixels(desired_rectangle, pixel_loader)Loads pixels partially by packs.
load_pixels(rectangle)Loads pixels.
load_raw_data(rectangle, dest_image_bounds, raw_data_settings, raw_data_loader)Loads raw data.
load_raw_data(rectangle, raw_data_settings, raw_data_loader)Loads raw data.
load_stream(stream)Loads a new image from the specified stream.
load_stream_with_options(stream, load_options)Loads a new image from the specified stream.
load_with_options(file_path, load_options)Loads a new image from the specified file.
normalize_angle()Normalizes the angle.
This method is applicable to scanned text documents to get rid of the skewed scan.
This method uses RasterImage.get_skew_angle() and RasterImage.rotate(angle) methods.
normalize_angle(resize_proportionally, background_color)Normalizes the angle.
This method is applicable to scanned text documents to get rid of the skewed scan.
This method uses RasterImage.get_skew_angle() and RasterImage.rotate(angle, resize_proportionally, background_color) methods.
read_argb_32_scan_line(scan_line_index)Reads the whole scan line by the specified scan line index.
read_scan_line(scan_line_index)Reads the whole scan line by the specified scan line index.
remove_metadata()Removes this image instance metadata by setting this IHasXmpData.xmp_data value to None.
replace_argb(old_color_argb, old_color_diff, new_color_argb)Replaces one color to another with allowed difference and preserves original alpha value to save smooth edges.
replace_color(old_color, old_color_diff, new_color)Replaces one color to another with allowed difference and preserves original alpha value to save smooth edges.
replace_color(old_color_argb, old_color_diff, new_color_argb)Replaces one color to another with allowed difference and preserves original alpha value to save smooth edges.
replace_non_transparent_colors(new_color)Replaces all non-transparent colors with new color and preserves original alpha value to save smooth edges.
Note: if you use it on images without transparency, all colors will be replaced with a single one.
replace_non_transparent_colors(new_color_argb)Replaces all non-transparent colors with new color and preserves original alpha value to save smooth edges.
Note: if you use it on images without transparency, all colors will be replaced with a single one.
resize(new_width, new_height)Resizes the image. The default ResizeType.NEAREST_NEIGHBOUR_RESAMPLE is used.
resize(new_width, new_height, resize_type)Resizes the image.
resize(new_width, new_height, settings)Resizes the image.
resize_by_settings(new_width, new_height, settings)Resizes the image.
resize_by_type(new_width, new_height, resize_type)Resizes the image.
resize_height_proportionally(new_height)Resizes the height proportionally. The default ResizeType.NEAREST_NEIGHBOUR_RESAMPLE is used.
resize_height_proportionally(new_height, resize_type)Resizes the height proportionally.
resize_height_proportionally(new_height, settings)Resizes the height proportionally.
resize_height_proportionally_settings(new_height, settings)Resizes the height proportionally.
resize_width_proportionally(new_width)Resizes the width proportionally. The default ResizeType.NEAREST_NEIGHBOUR_RESAMPLE is used.
resize_width_proportionally(new_width, resize_type)Resizes the width proportionally.
resize_width_proportionally(new_width, settings)Resizes the width proportionally.
resize_width_proportionally_settings(new_width, settings)Resizes the width proportionally.
rotate(angle)Rotate image around the center.
rotate(angle, resize_proportionally, background_color)Rotate image around the center.
rotate_flip(rotate_flip_type)Rotates, flips, or rotates and flips the image.
save()Saves the image data to the underlying stream.
save(file_path)Saves the image to the specified file location.
save(file_path, options)Saves the object’s data to the specified file location in the specified file format according to save options.
save(file_path, options, bounds_rectangle)Saves the object’s data to the specified file location in the specified file format according to save options.
save(file_path, over_write)Saves the object’s data to the specified file location.
save(stream)Saves the object’s data to the specified stream.
save(stream, options_base)Saves the image’s data to the specified stream in the specified file format according to save options.
save(stream, options_base, bounds_rectangle)Saves the image’s data to the specified stream in the specified file format according to save options.
save_argb_32_pixels(rectangle, pixels)Saves the 32-bit ARGB pixels.
save_cmyk_32_pixels(rectangle, pixels)Saves the pixels.
save_cmyk_pixels(rectangle, pixels)Saves the pixels.
This method is deprecated. Please use more effective the RasterImage.save_cmyk_32_pixels(rectangle, pixels) method.
save_pixels(rectangle, pixels)Saves pixels (format specific method).
save_raw_data(data, data_offset, rectangle, raw_data_settings)Saves the raw data.
save_to_stream(stream)Saves the object’s data to the specified stream.
save_to_stream_with_options(stream, options_base)Saves the image’s data to the specified stream in the specified file format according to save options.
save_to_stream_with_options_rect(stream, options_base, bounds_rectangle)Saves the image’s data to the specified stream in the specified file format according to save options.
save_with_options(file_path, options)Saves the object’s data to the specified file location in the specified file format according to save options.
save_with_options_rect(file_path, options, bounds_rectangle)Saves the object’s data to the specified file location in the specified file format according to save options.
set_argb_32_pixel(x, y, argb_32_color)Sets an image 32-bit ARGB pixel for the specified position.
set_palette(palette, update_colors)Sets the image palette.
set_pixel(x, y, color)Sets an image pixel for the specified position.
set_resolution(dpi_x, dpi_y)Adjust the resolution of your RasterImage effortlessly with this
user-friendly method. Perfect for developers seeking precise control over
image resolution in their applications.
write_argb_32_scan_line(scan_line_index, argb_32_pixels)Writes the whole scan line to the specified scan line index.
write_scan_line(scan_line_index, pixels)Writes the whole scan line to the specified scan line index.

Constructor: BmpImage(path)

 BmpImage(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.

Parameters:

ParameterTypeDescription
pathstringThe path to load image from and initialize pixel and palette data with.

See also:

Example # 1: The example shows how to load a BmpImage from a file.

Constructor: BmpImage(path, bits_per_pixel, compression, horizontal_resolution, vertical_resolution)

 BmpImage(path, bits_per_pixel, compression, horizontal_resolution, vertical_resolution) 

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.

Parameters:

ParameterTypeDescription
pathstringThe path to load image from and initialize pixel and palette data with.
bits_per_pixelushortThe bits per pixel.
compressionBitmapCompressionThe compression to use.
horizontal_resolutiondoubleThe horizontal resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.
vertical_resolutiondoubleThe vertical resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.

See also:

Example # 1: The example shows how to load a BmpImage from a file with the specified bit d…

Constructor: BmpImage(raster_image)

 BmpImage(raster_image) 

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.

Parameters:

ParameterTypeDescription
raster_imageRasterImageThe image to initialize pixel and palette data with.

See also:

Example # 1: The example shows how to load a BmpImage from another instance of RasterImage.

Constructor: BmpImage(raster_image, bits_per_pixel, compression, horizontal_resolution, vertical_resolution)

 BmpImage(raster_image, bits_per_pixel, compression, horizontal_resolution, vertical_resolution) 

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.

Parameters:

ParameterTypeDescription
raster_imageRasterImageThe image to initialize pixel and palette data with.
bits_per_pixelushortThe bits per pixel.
compressionBitmapCompressionThe compression to use.
horizontal_resolutiondoubleThe horizontal resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.
vertical_resolutiondoubleThe vertical resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.

See also:

Example # 1: The example shows how to load a BmpImage from another instance of RasterImage…

Constructor: BmpImage(stream)

 BmpImage(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.

Parameters:

ParameterTypeDescription
stream_io.BufferedRandomThe stream to load image from and initialize pixel and palette data with.

See also:

Example # 1: The example shows how to load a BmpImage from a file stream.

Constructor: BmpImage(stream, bits_per_pixel, compression, horizontal_resolution, vertical_resolution)

 BmpImage(stream, bits_per_pixel, compression, horizontal_resolution, vertical_resolution) 

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.

Parameters:

ParameterTypeDescription
stream_io.BufferedRandomThe stream to load image from and initialize pixel and palette data with.
bits_per_pixelushortThe bits per pixel.
compressionBitmapCompressionThe compression to use.
horizontal_resolutiondoubleThe horizontal resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.
vertical_resolutiondoubleThe vertical resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.

See also:

Example # 1: The example shows how to load a BmpImage from a file stream with the specifie…

Constructor: BmpImage(width, height)

 BmpImage(width, 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.

Parameters:

ParameterTypeDescription
widthintThe image width.
heightintThe image height.

See also:

Example # 1: The following example shows how to set a palette to a BMP image to reduce its…

Example # 2: The example shows how to create a BmpImage of the specified size.

Constructor: BmpImage(width, height, bits_per_pixel, palette)

 BmpImage(width, height, bits_per_pixel, 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.

Parameters:

ParameterTypeDescription
widthintThe image width.
heightintThe image height.
bits_per_pixelushortThe bits per pixel.
paletteIColorPaletteThe color palette.

See also:

Example # 1: The example shows how to create a BmpImage of the specified size with the spe…

Constructor: BmpImage(width, height, bits_per_pixel, palette, compression, horizontal_resolution, vertical_resolution)

 BmpImage(width, height, bits_per_pixel, palette, compression, horizontal_resolution, vertical_resolution) 

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.

Parameters:

ParameterTypeDescription
widthintThe image width.
heightintThe image height.
bits_per_pixelushortThe bits per pixel.
paletteIColorPaletteThe color palette.
compressionBitmapCompressionThe compression to use.
horizontal_resolutiondoubleThe horizontal resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.
vertical_resolutiondoubleThe vertical resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.

See also:

Example # 1: The example shows how to create a BmpImage using various options.

Property: bitmap_info_header

Quickly access essential details about your bitmap image with this straightforward function.
Perfect for developers needing to retrieve header information for their images.

See also:

Example # 1: The following example gets the information from the BMP header and prints it …

Property: bits_per_pixel

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.

See also:

Example # 1: The following example gets the general information about the image including …

Example # 2: The following example shows how the bitmap compression affects the output ima…

Property: compression

Retrieve the compression type used for the image effortlessly with this property.
Perfect for developers needing to quickly access information about image compression.

See also:

Example # 1: The following example gets the general information about the image including …

Example # 2: The following example shows how the bitmap compression affects the output ima…

Property: file_format

Easily retrieve the file format value with this user-friendly property.
Ideal for developers seeking quick access to information about the file format.

See also:

Example # 1: The following example shows how to extract information about raw data format …

Property: height

Retrieve the height of the image effortlessly with this property. Ideal for developers
needing quick access to information about image dimensions.

See also:

Example # 1: The following example gets the general information about the image including …

Example # 2: The following example shows how the bitmap compression affects the output ima…

Property: horizontal_resolution

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.

See also:

Example # 1: The following example gets the general information about the image including …

Example # 2: The following example shows how to set horizontal/vertical resolution of a BM…

Property: raw_data_format

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.

See also:

Example # 1: The following example gets the general information about the image including …

Example # 2: The following example shows how to extract information about raw data format …

Property: raw_line_size

Quickly access the size of each raw line in bytes with this straightforward property.
Ideal for developers needing to efficiently handle raw image data.

See also:

Example # 1: The following example gets the general information about the image including …

Example # 2: The following example shows how the bitmap compression affects the output ima…

Property: vertical_resolution

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.

See also:

Example # 1: The following example gets the general information about the image including …

Example # 2: The following example shows how to set horizontal/vertical resolution of a BM…

Property: width

Access the width of the image easily with this property. Ideal for developers
seeking quick information about the image dimensions.

See also:

Example # 1: The following example gets the general information about the image including …

Example # 2: The following example shows how the bitmap compression affects the output ima…

Method: adjust_brightness(brightness)

 adjust_brightness(brightness) 

Adjust of a brightness for image.

Parameters:

ParameterTypeDescription
brightnessintBrightness value.

Method: adjust_contrast(contrast)

 adjust_contrast(contrast) 

Image contrasting

Parameters:

ParameterTypeDescription
contrastfloatContrast value (in range [-100; 100])

Method: adjust_gamma(gamma)

 adjust_gamma(gamma) 

Gamma-correction of an image.

Parameters:

ParameterTypeDescription
gammafloatGamma for red, green and blue channels coefficient

Method: adjust_gamma(gamma_red, gamma_green, gamma_blue)

 adjust_gamma(gamma_red, gamma_green, gamma_blue) 

Gamma-correction of an image.

Parameters:

ParameterTypeDescription
gamma_redfloatGamma for red channel coefficient
gamma_greenfloatGamma for green channel coefficient
gamma_bluefloatGamma for blue channel coefficient

Method: binarize_bradley(brightness_difference)

 binarize_bradley(brightness_difference) 

Binarization of an image using Bradley’s adaptive thresholding algorithm using the integral image thresholding

Parameters:

ParameterTypeDescription
brightness_differencedoubleThe brightness difference between pixel and the average of an s x s window of pixels centered around this pixel.

Method: binarize_bradley(brightness_difference, window_size)

 binarize_bradley(brightness_difference, window_size) 

Binarization of an image using Bradley’s adaptive thresholding algorithm using the integral image thresholding

Parameters:

ParameterTypeDescription
brightness_differencedoubleThe brightness difference between pixel and the average of an s x s window of pixels centered around this pixel.
window_sizeintThe size of s x s window of pixels centered around this pixel

Method: binarize_fixed(threshold)

 binarize_fixed(threshold) 

Binarization of an image with predefined threshold

Parameters:

ParameterTypeDescription
thresholdbyteThreshold value. If corresponding gray value of a pixel is greater than threshold, a value of 255 will be assigned to it, 0 otherwise.

Method: blend(origin, overlay, overlay_alpha)

 blend(origin, overlay, overlay_alpha) 

Blends this image instance with the overlay image.

Parameters:

ParameterTypeDescription
originPointThe background image blending origin.
overlayRasterImageThe overlay image.
overlay_alphabyteThe overlay alpha.

Method: blend(origin, overlay, overlay_area, overlay_alpha)

 blend(origin, overlay, overlay_area, overlay_alpha) 

Blends this image instance with the overlay image.

Parameters:

ParameterTypeDescription
originPointThe background image blending origin.
overlayRasterImageThe overlay image.
overlay_areaRectangleThe overlay area.
overlay_alphabyteThe overlay alpha.

Method: can_load(file_path) [static]

 can_load(file_path) 

Determines whether image can be loaded from the specified file path.

Parameters:

ParameterTypeDescription
file_pathstringThe file path.

Returns

TypeDescription
booltrue if image can be loaded from the specified file; otherwise, false.

Method: can_load(file_path, load_options) [static]

 can_load(file_path, load_options) 

Determines whether image can be loaded from the specified file path and optionally using the specified open options.

Parameters:

ParameterTypeDescription
file_pathstringThe file path.
load_optionsLoadOptionsThe load options.

Returns

TypeDescription
booltrue if image can be loaded from the specified file; otherwise, false.

Method: can_load(stream) [static]

 can_load(stream) 

Determines whether image can be loaded from the specified stream.

Parameters:

ParameterTypeDescription
stream_io.BufferedRandomThe stream to load from.

Returns

TypeDescription
booltrue if image can be loaded from the specified stream; otherwise, false.

Method: can_load(stream, load_options) [static]

 can_load(stream, load_options) 

Determines whether image can be loaded from the specified stream and optionally using the specified loadOptions.

Parameters:

ParameterTypeDescription
stream_io.BufferedRandomThe stream to load from.
load_optionsLoadOptionsThe load options.

Returns

TypeDescription
booltrue if image can be loaded from the specified stream; otherwise, false.

Method: can_load_stream(stream) [static]

 can_load_stream(stream) 

Determines whether image can be loaded from the specified stream.

Parameters:

ParameterTypeDescription
stream_io.BufferedRandomThe stream to load from.

Returns

TypeDescription
booltrue if image can be loaded from the specified stream; otherwise, false.

Method: can_load_stream_with_options(stream, load_options) [static]

 can_load_stream_with_options(stream, load_options) 

Determines whether image can be loaded from the specified stream and optionally using the specified loadOptions.

Parameters:

ParameterTypeDescription
stream_io.BufferedRandomThe stream to load from.
load_optionsLoadOptionsThe load options.

Returns

TypeDescription
booltrue if image can be loaded from the specified stream; otherwise, false.

Method: can_load_with_options(file_path, load_options) [static]

 can_load_with_options(file_path, load_options) 

Determines whether image can be loaded from the specified file path and optionally using the specified open options.

Parameters:

ParameterTypeDescription
file_pathstringThe file path.
load_optionsLoadOptionsThe load options.

Returns

TypeDescription
booltrue if image can be loaded from the specified file; otherwise, false.

Method: can_save(options)

 can_save(options) 

Determines whether image can be saved to the specified file format represented by the passed save options.

Parameters:

ParameterTypeDescription
optionsImageOptionsBaseThe save options to use.

Returns

TypeDescription
booltrue if image can be saved to the specified file format represented by the passed save options; otherwise, false.

Method: create(image_options, width, height) [static]

 create(image_options, width, height) 

Creates a new image using the specified create options.

Parameters:

ParameterTypeDescription
image_optionsImageOptionsBaseThe image options.
widthintThe width.
heightintThe height.

Returns

TypeDescription
ImageThe newly created image.

Method: create(images) [static]

 create(images) 

Creates a new image using the specified images as pages

Parameters:

ParameterTypeDescription
imagesImage[]The images.

Returns

TypeDescription
ImageThe Image as IMultipageImage

Method: create(images, dispose_images) [static]

 create(images, dispose_images) 

Creates a new image the specified images as pages.

Parameters:

ParameterTypeDescription
imagesImage[]The images.
dispose_imagesboolif set to true [dispose images].

Returns

TypeDescription
ImageThe Image as IMultipageImage

Method: create_from_file_with_params(path, bits_per_pixel, compression, horizontal_resolution, vertical_resolution) [static]

 create_from_file_with_params(path, bits_per_pixel, compression, horizontal_resolution, vertical_resolution) 

Easily begin using the BmpImage class with this constructor, simplifying
the process of initializing a new instance. Ideal for developers seeking
a quick and efficient way to incorporate BmpImage objects into their projects.

Parameters:

ParameterTypeDescription
pathstringThe path to load image from and initialize pixel and palette data with.
bits_per_pixelushortThe bits per pixel.
compressionBitmapCompressionThe compression to use.
horizontal_resolutiondoubleThe horizontal resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.
vertical_resolutiondoubleThe vertical resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.

Returns

TypeDescription
BmpImage

Method: create_from_image(raster_image) [static]

 create_from_image(raster_image) 

Initializes a new instance of the BmpImage class.

Parameters:

ParameterTypeDescription
raster_imageRasterImageThe image to initialize pixel and palette data with.

Returns

TypeDescription
BmpImage

Method: create_from_image_with_params(raster_image, bits_per_pixel, compression, horizontal_resolution, vertical_resolution) [static]

 create_from_image_with_params(raster_image, bits_per_pixel, compression, horizontal_resolution, vertical_resolution) 

Initializes a new instance of the BmpImage class.

Parameters:

ParameterTypeDescription
raster_imageRasterImageThe image to initialize pixel and palette data with.
bits_per_pixelushortThe bits per pixel.
compressionBitmapCompressionThe compression to use.
horizontal_resolutiondoubleThe horizontal resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.
vertical_resolutiondoubleThe vertical resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.

Returns

TypeDescription
BmpImage

Method: create_from_stream(stream) [static]

 create_from_stream(stream) 

Initializes a new instance of the BmpImage class.

Parameters:

ParameterTypeDescription
stream_io.BufferedRandomThe stream to load image from and initialize pixel and palette data with.

Returns

TypeDescription
BmpImage

Method: create_from_stream_with_params(stream, bits_per_pixel, compression, horizontal_resolution, vertical_resolution) [static]

 create_from_stream_with_params(stream, bits_per_pixel, compression, horizontal_resolution, vertical_resolution) 

Initializes a new instance of the BmpImage class.

Parameters:

ParameterTypeDescription
stream_io.BufferedRandomThe stream to load image from and initialize pixel and palette data with.
bits_per_pixelushortThe bits per pixel.
compressionBitmapCompressionThe compression to use.
horizontal_resolutiondoubleThe horizontal resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.
vertical_resolutiondoubleThe vertical resolution. Note due to the rounding the resulting resolution may slightly differ from the passed.

Returns

TypeDescription
BmpImage

Method: crop(left_shift, right_shift, top_shift, bottom_shift)

 crop(left_shift, right_shift, top_shift, bottom_shift) 

Crop image with shifts.

Parameters:

ParameterTypeDescription
left_shiftintThe left shift.
right_shiftintThe right shift.
top_shiftintThe top shift.
bottom_shiftintThe bottom shift.

Method: crop(rectangle)

 crop(rectangle) 

Cropping the image.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle.

Method: dither(dithering_method, bits_count)

 dither(dithering_method, bits_count) 

Performs dithering on the current image.

Parameters:

ParameterTypeDescription
dithering_methodDitheringMethodThe dithering method.
bits_countintThe final bits count for dithering.

Method: dither(dithering_method, bits_count, custom_palette)

 dither(dithering_method, bits_count, custom_palette) 

Performs dithering on the current image.

Parameters:

ParameterTypeDescription
dithering_methodDitheringMethodThe dithering method.
bits_countintThe final bits count for dithering.
custom_paletteIColorPaletteThe custom palette for dithering.

Method: filter(rectangle, options)

 filter(rectangle, options) 

Filters the specified rectangle.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle.
optionsFilterOptionsBaseThe options.

Method: get_argb_32_pixel(x, y)

 get_argb_32_pixel(x, y) 

Gets an image 32-bit ARGB pixel.

Parameters:

ParameterTypeDescription
xintThe pixel x location.
yintThe pixel y location.

Returns

TypeDescription
intThe 32-bit ARGB pixel for the specified location.

Method: get_default_argb_32_pixels(rectangle)

 get_default_argb_32_pixels(rectangle) 

Gets the default 32-bit ARGB pixels array.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to get pixels for.

Returns

TypeDescription
intThe default pixels array.

Method: get_default_options(args)

 get_default_options(args) 

Retrieve the default options effortlessly with this straightforward method.
Ideal for developers seeking quick access to default image settings or configurations.

Parameters:

ParameterTypeDescription
argsobjectThe arguments.

Returns

TypeDescription
ImageOptionsBaseDefault options

Method: get_default_pixels(rectangle, partial_pixel_loader)

 get_default_pixels(rectangle, partial_pixel_loader) 

Gets the default pixels array using partial pixel loader.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to get pixels for.
partial_pixel_loaderIPartialArgb32PixelLoaderThe partial pixel loader.

Method: get_default_raw_data(rectangle, partial_raw_data_loader, raw_data_settings)

 get_default_raw_data(rectangle, partial_raw_data_loader, raw_data_settings) 

Gets the default raw data array using partial pixel loader.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to get pixels for.
partial_raw_data_loaderIPartialRawDataLoaderThe partial raw data loader.
raw_data_settingsRawDataSettingsThe raw data settings.

Method: get_default_raw_data(rectangle, raw_data_settings)

 get_default_raw_data(rectangle, raw_data_settings) 

Gets the default raw data array.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to get raw data for.
raw_data_settingsRawDataSettingsThe raw data settings.

Returns

TypeDescription
byteThe default raw data array.

Method: get_file_format(file_path) [static]

 get_file_format(file_path) 

Gets the file format.

Parameters:

ParameterTypeDescription
file_pathstringThe file path.

Returns

TypeDescription
FileFormatThe determined file format.

Method: get_file_format(stream) [static]

 get_file_format(stream) 

Gets the file format.

Parameters:

ParameterTypeDescription
stream_io.BufferedRandomThe stream.

Returns

TypeDescription
FileFormatThe determined file format.

Method: get_file_format_of_stream(stream) [static]

 get_file_format_of_stream(stream) 

Gets the file format.

Parameters:

ParameterTypeDescription
stream_io.BufferedRandomThe stream.

Returns

TypeDescription
FileFormatThe determined file format.

Method: get_fitting_rectangle(rectangle, pixels, width, height) [static]

 get_fitting_rectangle(rectangle, pixels, width, height) 

Gets rectangle which fits the current image.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to get fitting rectangle for.
pixelsintThe 32-bit ARGB pixels.
widthintThe object width.
heightintThe object height.

Returns

TypeDescription
RectangleThe fitting rectangle or exception if no fitting rectangle can be found.

Method: get_fitting_rectangle(rectangle, width, height) [static]

 get_fitting_rectangle(rectangle, width, height) 

Gets rectangle which fits the current image.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to get fitting rectangle for.
widthintThe object width.
heightintThe object height.

Returns

TypeDescription
RectangleThe fitting rectangle or exception if no fitting rectangle can be found.

Method: get_modify_date(use_default)

 get_modify_date(use_default) 

Gets the date and time the resource image was last modified.

Parameters:

ParameterTypeDescription
use_defaultboolif set to true uses the information from FileInfo as default value.

Returns

TypeDescription
datetimeThe date and time the resource image was last modified.

Method: get_original_options()

 get_original_options() 

Gets the options based on the original file settings.
This can be helpful to keep bit-depth and other parameters of the original image unchanged.
For example, if we load a black-white PNG image with 1 bit per pixel and then save it using the
DataStreamSupporter.save(file_path) method, the output PNG image with 8-bit per pixel will be produced.
To avoid it and save PNG image with 1-bit per pixel, use this method to get corresponding saving options and pass them
to the Image.save(file_path, options) method as the second parameter.

Returns

TypeDescription
ImageOptionsBaseThe options based on the original file settings.

Method: get_pixel(x, y)

 get_pixel(x, y) 

Gets an image pixel.

Parameters:

ParameterTypeDescription
xintThe pixel x location.
yintThe pixel y location.

Returns

TypeDescription
ColorThe pixel color for the specified location.

Method: get_proportional_height(width, height, new_width) [static]

 get_proportional_height(width, height, new_width) 

Gets a proportional height.

Parameters:

ParameterTypeDescription
widthintThe width.
heightintThe height.
new_widthintThe new width.

Returns

TypeDescription
intThe proportional height.

Method: get_proportional_width(width, height, new_height) [static]

 get_proportional_width(width, height, new_height) 

Gets a proportional width.

Parameters:

ParameterTypeDescription
widthintThe width.
heightintThe height.
new_heightintThe new height.

Returns

TypeDescription
intThe proportional width.

Method: get_serialized_stream(image_options, clipping_rectangle, page_number)

 get_serialized_stream(image_options, clipping_rectangle, page_number) 

Converts to aps.

Parameters:

ParameterTypeDescription
image_optionsImageOptionsBaseThe image options.
clipping_rectangleRectangleThe clipping rectangle.
page_numberint[]The page number.

Returns

TypeDescription
_io.BufferedRandomThe serialized stream

Method: get_skew_angle()

 get_skew_angle() 

Gets the skew angle.
This method is applicable to scanned text documents, to determine the skew angle when scanning.

Returns

TypeDescription
floatThe skew angle, in degrees.

Method: load(file_path) [static]

 load(file_path) 

Loads a new image from the specified file.

Parameters:

ParameterTypeDescription
file_pathstringThe file path to load image from.

Returns

TypeDescription
ImageThe loaded image.

Method: load(file_path, load_options) [static]

 load(file_path, load_options) 

Loads a new image from the specified file.

Parameters:

ParameterTypeDescription
file_pathstringThe file path to load image from.
load_optionsLoadOptionsThe load options.

Returns

TypeDescription
ImageThe loaded image.

Method: load(stream) [static]

 load(stream) 

Loads a new image from the specified stream.

Parameters:

ParameterTypeDescription
stream_io.BufferedRandomThe stream to load image from.

Returns

TypeDescription
ImageThe loaded image.

Method: load(stream, load_options) [static]

 load(stream, load_options) 

Loads a new image from the specified stream.

Parameters:

ParameterTypeDescription
stream_io.BufferedRandomThe stream to load image from.
load_optionsLoadOptionsThe load options.

Returns

TypeDescription
ImageThe loaded image.

Method: load_argb_32_pixels(rectangle)

 load_argb_32_pixels(rectangle) 

Loads 32-bit ARGB pixels.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to load pixels from.

Returns

TypeDescription
intThe loaded 32-bit ARGB pixels array.

Method: load_argb_64_pixels(rectangle)

 load_argb_64_pixels(rectangle) 

Loads 64-bit ARGB pixels.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to load pixels from.

Returns

TypeDescription
longThe loaded 64-bit ARGB pixels array.

Method: load_cmyk_32_pixels(rectangle)

 load_cmyk_32_pixels(rectangle) 

Loads pixels in CMYK format.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to load pixels from.

Returns

TypeDescription
intThe loaded CMYK pixels presentes as 32-bit inateger values.

Method: load_cmyk_pixels(rectangle)

 load_cmyk_pixels(rectangle) 

Loads pixels in CMYK format.
This method is deprecated. Please use more effective the RasterImage.load_cmyk_32_pixels(rectangle) method.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to load pixels from.

Returns

TypeDescription
CmykColor[]The loaded CMYK pixels array.

Method: load_partial_argb_32_pixels(rectangle, partial_pixel_loader)

 load_partial_argb_32_pixels(rectangle, partial_pixel_loader) 

Loads 32-bit ARGB pixels partially (by blocks).

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to load pixels from.
partial_pixel_loaderIPartialArgb32PixelLoaderThe partial pixel loader.

Method: load_partial_argb_64_pixels(rectangle, partial_pixel_loader)

 load_partial_argb_64_pixels(rectangle, partial_pixel_loader) 

Loads 64-bit ARGB pixels partially by packs.

Parameters:

ParameterTypeDescription
rectangleRectangleThe desired rectangle.
partial_pixel_loaderIPartialArgb64PixelLoaderThe 64-bit ARGB pixel loader.

Method: load_partial_pixels(desired_rectangle, pixel_loader)

 load_partial_pixels(desired_rectangle, pixel_loader) 

Loads pixels partially by packs.

Parameters:

ParameterTypeDescription
desired_rectangleRectangleThe desired rectangle.
pixel_loaderIPartialPixelLoaderThe pixel loader.

Method: load_pixels(rectangle)

 load_pixels(rectangle) 

Loads pixels.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to load pixels from.

Returns

TypeDescription
Color[]The loaded pixels array.

Method: load_raw_data(rectangle, dest_image_bounds, raw_data_settings, raw_data_loader)

 load_raw_data(rectangle, dest_image_bounds, raw_data_settings, raw_data_loader) 

Loads raw data.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to load raw data from.
dest_image_boundsRectangleThe dest image bounds.
raw_data_settingsRawDataSettingsThe raw data settings to use for loaded data. Note if data is not in the format specified then data conversion will be performed.
raw_data_loaderIPartialRawDataLoaderThe raw data loader.

Method: load_raw_data(rectangle, raw_data_settings, raw_data_loader)

 load_raw_data(rectangle, raw_data_settings, raw_data_loader) 

Loads raw data.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to load raw data from.
raw_data_settingsRawDataSettingsThe raw data settings to use for loaded data. Note if data is not in the format specified then data conversion will be performed.
raw_data_loaderIPartialRawDataLoaderThe raw data loader.

Method: load_stream(stream) [static]

 load_stream(stream) 

Loads a new image from the specified stream.

Parameters:

ParameterTypeDescription
stream_io.BufferedRandomThe stream to load image from.

Returns

TypeDescription
ImageThe loaded image.

Method: load_stream_with_options(stream, load_options) [static]

 load_stream_with_options(stream, load_options) 

Loads a new image from the specified stream.

Parameters:

ParameterTypeDescription
stream_io.BufferedRandomThe stream to load image from.
load_optionsLoadOptionsThe load options.

Returns

TypeDescription
ImageThe loaded image.

Method: load_with_options(file_path, load_options) [static]

 load_with_options(file_path, load_options) 

Loads a new image from the specified file.

Parameters:

ParameterTypeDescription
file_pathstringThe file path to load image from.
load_optionsLoadOptionsThe load options.

Returns

TypeDescription
ImageThe loaded image.

Method: normalize_angle(resize_proportionally, background_color)

 normalize_angle(resize_proportionally, background_color) 

Normalizes the angle.
This method is applicable to scanned text documents to get rid of the skewed scan.
This method uses RasterImage.get_skew_angle() and RasterImage.rotate(angle, resize_proportionally, background_color) methods.

Parameters:

ParameterTypeDescription
resize_proportionallyboolif set to true you will have your image size changed according to rotated rectangle (corner points) projections in other case that leaves dimensions untouched and only internal image contents are rotated.
background_colorColorColor of the background.

Method: read_argb_32_scan_line(scan_line_index)

 read_argb_32_scan_line(scan_line_index) 

Reads the whole scan line by the specified scan line index.

Parameters:

ParameterTypeDescription
scan_line_indexintZero based index of the scan line.

Returns

TypeDescription
intThe scan line 32-bit ARGB color values array.

Method: read_scan_line(scan_line_index)

 read_scan_line(scan_line_index) 

Reads the whole scan line by the specified scan line index.

Parameters:

ParameterTypeDescription
scan_line_indexintZero based index of the scan line.

Returns

TypeDescription
Color[]The scan line pixel color values array.

Method: replace_argb(old_color_argb, old_color_diff, new_color_argb)

 replace_argb(old_color_argb, old_color_diff, new_color_argb) 

Replaces one color to another with allowed difference and preserves original alpha value to save smooth edges.

Parameters:

ParameterTypeDescription
old_color_argbintOld color ARGB value to be replaced.
old_color_diffbyteAllowed difference in old color to be able to widen replaced color tone.
new_color_argbintNew color ARGB value to replace old color with.

Method: replace_color(old_color, old_color_diff, new_color)

 replace_color(old_color, old_color_diff, new_color) 

Replaces one color to another with allowed difference and preserves original alpha value to save smooth edges.

Parameters:

ParameterTypeDescription
old_colorColorOld color to be replaced.
old_color_diffbyteAllowed difference in old color to be able to widen replaced color tone.
new_colorColorNew color to replace old color with.

Method: replace_color(old_color_argb, old_color_diff, new_color_argb)

 replace_color(old_color_argb, old_color_diff, new_color_argb) 

Replaces one color to another with allowed difference and preserves original alpha value to save smooth edges.

Parameters:

ParameterTypeDescription
old_color_argbintOld color ARGB value to be replaced.
old_color_diffbyteAllowed difference in old color to be able to widen replaced color tone.
new_color_argbintNew color ARGB value to replace old color with.

Method: replace_non_transparent_colors(new_color)

 replace_non_transparent_colors(new_color) 

Replaces all non-transparent colors with new color and preserves original alpha value to save smooth edges.
Note: if you use it on images without transparency, all colors will be replaced with a single one.

Parameters:

ParameterTypeDescription
new_colorColorNew color to replace non transparent colors with.

Method: replace_non_transparent_colors(new_color_argb)

 replace_non_transparent_colors(new_color_argb) 

Replaces all non-transparent colors with new color and preserves original alpha value to save smooth edges.
Note: if you use it on images without transparency, all colors will be replaced with a single one.

Parameters:

ParameterTypeDescription
new_color_argbintNew color ARGB value to replace non transparent colors with.

Method: resize(new_width, new_height)

 resize(new_width, new_height) 

Resizes the image. The default ResizeType.NEAREST_NEIGHBOUR_RESAMPLE is used.

Parameters:

ParameterTypeDescription
new_widthintThe new width.
new_heightintThe new height.

Method: resize(new_width, new_height, resize_type)

 resize(new_width, new_height, resize_type) 

Resizes the image.

Parameters:

ParameterTypeDescription
new_widthintThe new width.
new_heightintThe new height.
resize_typeResizeTypeThe resize type.

Method: resize(new_width, new_height, settings)

 resize(new_width, new_height, settings) 

Resizes the image.

Parameters:

ParameterTypeDescription
new_widthintThe new width.
new_heightintThe new height.
settingsImageResizeSettingsThe resize settings.

Method: resize_by_settings(new_width, new_height, settings)

 resize_by_settings(new_width, new_height, settings) 

Resizes the image.

Parameters:

ParameterTypeDescription
new_widthintThe new width.
new_heightintThe new height.
settingsImageResizeSettingsThe resize settings.

Method: resize_by_type(new_width, new_height, resize_type)

 resize_by_type(new_width, new_height, resize_type) 

Resizes the image.

Parameters:

ParameterTypeDescription
new_widthintThe new width.
new_heightintThe new height.
resize_typeResizeTypeThe resize type.

Method: resize_height_proportionally(new_height)

 resize_height_proportionally(new_height) 

Resizes the height proportionally. The default ResizeType.NEAREST_NEIGHBOUR_RESAMPLE is used.

Parameters:

ParameterTypeDescription
new_heightintThe new height.

Method: resize_height_proportionally(new_height, resize_type)

 resize_height_proportionally(new_height, resize_type) 

Resizes the height proportionally.

Parameters:

ParameterTypeDescription
new_heightintThe new height.
resize_typeResizeTypeType of the resize.

Method: resize_height_proportionally(new_height, settings)

 resize_height_proportionally(new_height, settings) 

Resizes the height proportionally.

Parameters:

ParameterTypeDescription
new_heightintThe new height.
settingsImageResizeSettingsThe image resize settings.

Method: resize_height_proportionally_settings(new_height, settings)

 resize_height_proportionally_settings(new_height, settings) 

Resizes the height proportionally.

Parameters:

ParameterTypeDescription
new_heightintThe new height.
settingsImageResizeSettingsThe image resize settings.

Method: resize_width_proportionally(new_width)

 resize_width_proportionally(new_width) 

Resizes the width proportionally. The default ResizeType.NEAREST_NEIGHBOUR_RESAMPLE is used.

Parameters:

ParameterTypeDescription
new_widthintThe new width.

Method: resize_width_proportionally(new_width, resize_type)

 resize_width_proportionally(new_width, resize_type) 

Resizes the width proportionally.

Parameters:

ParameterTypeDescription
new_widthintThe new width.
resize_typeResizeTypeType of the resize.

Method: resize_width_proportionally(new_width, settings)

 resize_width_proportionally(new_width, settings) 

Resizes the width proportionally.

Parameters:

ParameterTypeDescription
new_widthintThe new width.
settingsImageResizeSettingsThe image resize settings.

Method: resize_width_proportionally_settings(new_width, settings)

 resize_width_proportionally_settings(new_width, settings) 

Resizes the width proportionally.

Parameters:

ParameterTypeDescription
new_widthintThe new width.
settingsImageResizeSettingsThe image resize settings.

Method: rotate(angle)

 rotate(angle) 

Rotate image around the center.

Parameters:

ParameterTypeDescription
anglefloatThe rotate angle in degrees. Positive values will rotate clockwise.

Method: rotate(angle, resize_proportionally, background_color)

 rotate(angle, resize_proportionally, background_color) 

Rotate image around the center.

Parameters:

ParameterTypeDescription
anglefloatThe rotate angle in degrees. Positive values will rotate clockwise.
resize_proportionallyboolif set to true you will have your image size changed according to rotated rectangle (corner points) projections in other case that leaves dimensions untouched and only internal image contents are rotated.
background_colorColorColor of the background.

Method: rotate_flip(rotate_flip_type)

 rotate_flip(rotate_flip_type) 

Rotates, flips, or rotates and flips the image.

Parameters:

ParameterTypeDescription
rotate_flip_typeRotateFlipTypeThe rotate flip type.

Method: save(file_path)

 save(file_path) 

Saves the image to the specified file location.

Parameters:

ParameterTypeDescription
file_pathstringThe file path to save the image to.

Method: save(file_path, options)

 save(file_path, options) 

Saves the object’s data to the specified file location in the specified file format according to save options.

Parameters:

ParameterTypeDescription
file_pathstringThe file path.
optionsImageOptionsBaseThe options.

Method: save(file_path, options, bounds_rectangle)

 save(file_path, options, bounds_rectangle) 

Saves the object’s data to the specified file location in the specified file format according to save options.

Parameters:

ParameterTypeDescription
file_pathstringThe file path.
optionsImageOptionsBaseThe options.
bounds_rectangleRectangleThe destination image bounds rectangle. Set the empty rectangle for use sourse bounds.

Method: save(file_path, over_write)

 save(file_path, over_write) 

Saves the object’s data to the specified file location.

Parameters:

ParameterTypeDescription
file_pathstringThe file path to save the object’s data to.
over_writeboolif set to true over write the file contents, otherwise append will occur.

Method: save(stream)

 save(stream) 

Saves the object’s data to the specified stream.

Parameters:

ParameterTypeDescription
stream_io.BufferedRandomThe stream to save the object’s data to.

Method: save(stream, options_base)

 save(stream, options_base) 

Saves the image’s data to the specified stream in the specified file format according to save options.

Parameters:

ParameterTypeDescription
stream_io.BufferedRandomThe stream to save the image’s data to.
options_baseImageOptionsBaseThe save options.

Method: save(stream, options_base, bounds_rectangle)

 save(stream, options_base, bounds_rectangle) 

Saves the image’s data to the specified stream in the specified file format according to save options.

Parameters:

ParameterTypeDescription
stream_io.BufferedRandomThe stream to save the image’s data to.
options_baseImageOptionsBaseThe save options.
bounds_rectangleRectangleThe destination image bounds rectangle. Set the empty rectangle for use source bounds.

Method: save_argb_32_pixels(rectangle, pixels)

 save_argb_32_pixels(rectangle, pixels) 

Saves the 32-bit ARGB pixels.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to save pixels to.
pixelsintThe 32-bit ARGB pixels array.

Method: save_cmyk_32_pixels(rectangle, pixels)

 save_cmyk_32_pixels(rectangle, pixels) 

Saves the pixels.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to save pixels to.
pixelsintThe CMYK pixels presented as the 32-bit integer values.

Method: save_cmyk_pixels(rectangle, pixels)

 save_cmyk_pixels(rectangle, pixels) 

Saves the pixels.
This method is deprecated. Please use more effective the RasterImage.save_cmyk_32_pixels(rectangle, pixels) method.

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to save pixels to.
pixelsCmykColor[]The CMYK pixels array.

Method: save_pixels(rectangle, pixels)

 save_pixels(rectangle, pixels) 

Saves pixels (format specific method).

Parameters:

ParameterTypeDescription
rectangleRectangleThe rectangle to save pixels to.
pixelsColor[]The 32-bit ARGB pixels array.

Method: save_raw_data(data, data_offset, rectangle, raw_data_settings)

 save_raw_data(data, data_offset, rectangle, raw_data_settings) 

Saves the raw data.

Parameters:

ParameterTypeDescription
databyteThe raw data.
data_offsetintThe starting raw data offset.
rectangleRectangleThe raw data rectangle.
raw_data_settingsRawDataSettingsThe raw data settings the data is in.

Method: save_to_stream(stream)

 save_to_stream(stream) 

Saves the object’s data to the specified stream.

Parameters:

ParameterTypeDescription
stream_io.BufferedRandomThe stream to save the object’s data to.

Method: save_to_stream_with_options(stream, options_base)

 save_to_stream_with_options(stream, options_base) 

Saves the image’s data to the specified stream in the specified file format according to save options.

Parameters:

ParameterTypeDescription
stream_io.BufferedRandomThe stream to save the image’s data to.
options_baseImageOptionsBaseThe save options.

Method: save_to_stream_with_options_rect(stream, options_base, bounds_rectangle)

 save_to_stream_with_options_rect(stream, options_base, bounds_rectangle) 

Saves the image’s data to the specified stream in the specified file format according to save options.

Parameters:

ParameterTypeDescription
stream_io.BufferedRandomThe stream to save the image’s data to.
options_baseImageOptionsBaseThe save options.
bounds_rectangleRectangleThe destination image bounds rectangle. Set the empty rectangle for use source bounds.

Method: save_with_options(file_path, options)

 save_with_options(file_path, options) 

Saves the object’s data to the specified file location in the specified file format according to save options.

Parameters:

ParameterTypeDescription
file_pathstringThe file path.
optionsImageOptionsBaseThe options.

Method: save_with_options_rect(file_path, options, bounds_rectangle)

 save_with_options_rect(file_path, options, bounds_rectangle) 

Saves the object’s data to the specified file location in the specified file format according to save options.

Parameters:

ParameterTypeDescription
file_pathstringThe file path.
optionsImageOptionsBaseThe options.
bounds_rectangleRectangleThe destination image bounds rectangle. Set the empty rectangle for use sourse bounds.

Method: set_argb_32_pixel(x, y, argb_32_color)

 set_argb_32_pixel(x, y, argb_32_color) 

Sets an image 32-bit ARGB pixel for the specified position.

Parameters:

ParameterTypeDescription
xintThe pixel x location.
yintThe pixel y location.
argb_32_colorintThe 32-bit ARGB pixel for the specified position.

Method: set_palette(palette, update_colors)

 set_palette(palette, update_colors) 

Sets the image palette.

Parameters:

ParameterTypeDescription
paletteIColorPaletteThe palette to set.
update_colorsboolif set to true colors will be updated according to the new palette; otherwise color indexes remain unchanged. Note that unchanged indexes may crash the image on loading if some indexes have no corresponding palette entries.

Method: set_pixel(x, y, color)

 set_pixel(x, y, color) 

Sets an image pixel for the specified position.

Parameters:

ParameterTypeDescription
xintThe pixel x location.
yintThe pixel y location.
colorColorThe pixel color for the specified position.

Method: set_resolution(dpi_x, dpi_y)

 set_resolution(dpi_x, dpi_y) 

Adjust the resolution of your RasterImage effortlessly with this
user-friendly method. Perfect for developers seeking precise control over
image resolution in their applications.

Parameters:

ParameterTypeDescription
dpi_xdoubleThe horizontal resolution, in dots per inch, of the RasterImage.
dpi_ydoubleThe vertical resolution, in dots per inch, of the RasterImage.

See also:

Example # 1: The following example gets the general information about the image including …

Example # 2: The following example shows how to set horizontal/vertical resolution of a BM…

Method: write_argb_32_scan_line(scan_line_index, argb_32_pixels)

 write_argb_32_scan_line(scan_line_index, argb_32_pixels) 

Writes the whole scan line to the specified scan line index.

Parameters:

ParameterTypeDescription
scan_line_indexintZero based index of the scan line.
argb_32_pixelsintThe 32-bit ARGB colors array to write.

Method: write_scan_line(scan_line_index, pixels)

 write_scan_line(scan_line_index, pixels) 

Writes the whole scan line to the specified scan line index.

Parameters:

ParameterTypeDescription
scan_line_indexintZero based index of the scan line.
pixelsColor[]The pixel colors array to write.

Examples

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

from aspose.imaging import Color
from aspose.imaging.fileformats.bmp import BmpImage
from os.path import join as path_join

directory = "c:\\temp\\"

# Create a BMP image 100 x 100 px.
with BmpImage(100, 100) as bmpImage:
	# Fill the image with a simple linear red-black gradient.
	width = bmpImage.width
	height = bmpImage.height
	for y in range(height):
		for x in range(width):
			hue = (255 * x) // width
			bmpImage.set_pixel(x, y, Color.from_argb(255, hue, 0, 0))

	with open(path_join(directory, "output.bmp"), "w+b") as stream:
		bmpImage.save(stream)

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


from aspose.pycore import as_of
from aspose.imaging import Image
from aspose.imaging.fileformats.bmp import BmpImage
from os.path import join as path_join


with Image.load(r"c:\temp\sample.bmp") as image:
	bmpImage = as_of(image, BmpImage)    

	print("The pixel format:", bmpImage.raw_data_format)
	print("The raw line size in bytes:", bmpImage.raw_line_size)
	print("The bitmap compression:", bmpImage.compression)
	print("The bitmap width", bmpImage.width)
	print("The bitmap height", bmpImage.height)
	print("The number of bits per pixel", bmpImage.bits_per_pixel)

	hres = bmpImage.horizontal_resolution
	vres = bmpImage.vertical_resolution
	print("The horizontal resolution, in pixels per inch:", hres)
	print("The vertical resolution, in pixels per inch:", vres)

	if hres != 96.0 or vres != 96.0:
		# You may consider using the SetResolution method for updating both resolution values in single call.
		print("Set resolution values to 96 dpi")
		bmpImage.set_resolution(96.0, 96.0)
		print("The horizontal resolution, in pixels per inch: {0}", bmpImage.horizontal_resolution);
		print("The vertical resolution, in pixels per inch: {0}", bmpImage.vertical_resolution);

	#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: Rgb
	#The bitmap width: 500
	#The bitmap height: 375
	#The number of bits per pixel: 24
	#The horizontal resolution, in pixels per inch: 0
	#The vertical resolution, in pixels per inch: 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

The following example shows how to set a palette to a BMP image to reduce its output size.


from aspose.pycore import as_of
from aspose.imaging import Point, Color, Graphics, ColorPaletteHelper
from aspose.imaging.brushes import LinearGradientBrush
from aspose.imaging.fileformats.bmp import BmpImage
from aspose.imaging.imageoptions import BmpOptions
from os.path import join as path_join

# Create a BMP image 100 x 100 px.
with BmpImage(100, 100) as bmpImage:
	# The linear gradient from the left-top to the right-bottom corner of the image.
	brush = LinearGradientBrush(Point(0, 0), Point(bmpImage.width, bmpImage.height),
								Color.red,
								Color.green)
	# Fill the entire image with the linear gradient brush.
	gr = Graphics(bmpImage)
	gr.fill_rectangle(brush, bmpImage.bounds)
	# Get the closest 8-bit color palette which covers as many pixels as possible, so that a palettized image
	# is almost visually indistinguishable from a bmp without palette
	palette = ColorPaletteHelper.get_close_image_palette(bmpImage, 256)
	# 8-bit palette contains at most 256 colors.
	saveOptions = BmpOptions()
	saveOptions.palette = palette
	saveOptions.bits_per_pixel = 8
	
	with stream_ext.create_memory_stream() as stream:
		bmpImage.save(stream, saveOptions)
		print(f"The size of image with palette is {stream.tell()} bytes.")
		stream.seek(0)
		bmpImage.save(stream)
		print(f"The size of image without palette is {stream.tell()} bytes.")

# The output looks like this:
# The size of image with palette is 11078 bytes.
# The size of image without palette is 40054 bytes.

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

from aspose.imaging.fileformats.bmp import BmpImage
import os

directory = r"c:\temp"

# Load a BMP image from a file.
# The source pixels will be converted to 32-bpp format if required.
with BmpImage(os.path.join(directory, "sample.bmp")) as bmp_image:
	# Do some image processing.
	# Save to another BMP file.
	bmp_image.save(os.path.join(directory, "sample.output.32bpp.bmp"))

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

from aspose.imaging.fileformats.bmp import BmpImage, BitmapCompression
import os

directory = r"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.
with BmpImage(os.path.join(directory, "sample.bmp"), 24, BitmapCompression.RGB, 96.0, 96.0) as bmp_image:
	# Do some image processing.
	# Save to another BMP file.
	bmp_image.save(os.path.join(directory, "sample.output.24bpp.96dpi.bmp"))

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

from aspose.imaging.fileformats.bmp import BmpImage
import os

directory = r"c:\temp"

# Load a BMP image from a file stream.
# The source pixels will be converted to 32-bpp format if required.
with open(os.path.join(directory, "sample.bmp"), "rb+") as stream:
	with BmpImage(stream) as bmp_image:
		# Do some image processing.
		# Save to another BMP file.
		bmp_image.save(os.path.join(directory, "sample.output.32bpp.bmp"))

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

from aspose.imaging.fileformats.bmp import BmpImage, BitmapCompression
import os

directory = r"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.
with open(os.path.join(directory, "sample.bmp"), "rb") as stream:
	with BmpImage(stream, 24, BitmapCompression.RGB, 96.0, 96.0) as bmp_image:
		# Do some image processing.
		# Save to another BMP file.
		bmp_image.save(os.path.join(directory, "sample.output.24bpp.96dpi.bmp"))

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

from aspose.imaging.fileformats.bmp import BmpImage
from aspose.imaging.imageoptions import PngOptions
from aspose.imaging.sources import StreamSource
from aspose.imaging import Image, RasterImage, Graphics, Color
from aspose.imaging.brushes import SolidBrush
import os
import aspose.pycore as aspycore

directory = r"c:\temp"

# Create a new PNG image.
with PngOptions() as create_options:
	create_options.source = StreamSource()
	with aspycore.as_of(Image.create(create_options, 100, 100), RasterImage) as raster_image:
		# Fill the entire PNG image in red.
		gr = Graphics(raster_image)
		brush = SolidBrush(Color.red)
		gr.fill_rectangle(brush, raster_image.bounds)

		# Create a BMP image based on the PNG image.
		# The source pixels will be converted to 32-bpp format if required.
		with BmpImage(raster_image) as bmp_image:
			# Save to a BMP file
			bmp_image.save(os.path.join(directory, "output.32bpp.bmp"))

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


from aspose.imaging.fileformats.bmp import BmpImage, BitmapCompression
from aspose.imaging.imageoptions import PngOptions
from aspose.imaging.sources import StreamSource
from aspose.imaging import Image, RasterImage, Graphics, Color
from aspose.imaging.brushes import SolidBrush
import os
import aspose.pycore as aspycore

directory = r"c:\temp"

# Create a new PNG image.
with PngOptions() as create_options:
	create_options.source = StreamSource()
	with aspycore.as_of(Image.create(create_options, 100, 100), RasterImage) as raster_image:
		# Fill the entire PNG image in red.
		gr = Graphics(raster_image)
		brush = SolidBrush(Color.red)
		gr.fill_rectangle(brush, raster_image.bounds)

		# 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.
		with BmpImage(raster_image, 24, BitmapCompression.RGB, 96.0, 96.0) as bmp_image:
			# Save to a BMP file
			bmp_image.save(os.path.join(directory, "output.24bpp.96dpi.bmp"))

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

from aspose.imaging.fileformats.bmp import BmpImage
from aspose.imaging import Graphics, Color
from aspose.imaging.brushes import SolidBrush
import os

directory = r"c:\temp"

# Create a 32-bpp BMP image of 100 x 100 px.
with BmpImage(100, 100) as bmp_image:
	# Fill the entire image in red.
	Graphics gr = Graphics(bmp_image)
	brush = SolidBrush(Color.red)
	gr.fill_rectangle(brush, bmp_image.bounds)
	# Save to a BMP file
	bmp_image.save(os.path.join(directory, "output.bmp"))

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

from aspose.imaging.fileformats.bmp import BmpImage
from aspose.imaging import Graphics, Color, ColorPalette, Rectangle
from aspose.imaging.brushes import SolidBrush
import os

directory = r"c:\temp"

paletterColors = [Color.red, Color.green]

# Create a monochrome palette which contains only red and green colors.
palette = ColorPalette.create_with_colors(paletterColors)

# Create a monochrome 1-bpp BMP image of 100 x 100 px.
with BmpImage(100, 100, 1, palette) as bmp_image:
	gr = Graphics(bmp_image)

	# Fill the upper half of the image in red.
	redBrush = SolidBrush(Color.red)
	gr.fill_rectangle(redBrush, Rectangle(0, 0, bmp_image.width, bmp_image.height // 2))

	# Fill the lower half of the image in green.
	greenBrush = SolidBrush(Color.green)
	gr.fill_rectangle(greenBrush, Rectangle(0, bmp_image.height // 2, bmp_image.width, bmp_image.height // 2))

	# Save to BMP
	bmp_image.save(os.path.join(directory, "output.monochrome.bmp"))

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

from aspose.imaging.fileformats.bmp import BmpImage, BitmapCompression
from aspose.imaging import Graphics, Color, ColorPalette, Rectangle
from aspose.imaging.brushes import SolidBrush
import os

directory = r"c:\temp"

paletterColors = [Color.red, Color.green]

# Create a monochrome palette which contains only red and green colors.
palette = ColorPalette.create_with_colors(paletterColors)

# Create a monochrome 1-bpp BMP image of 100 x 100 px.
with BmpImage(100, 100, 1, palette, BitmapCompression.RGB, 96.0, 96.0) as bmp_image:
	gr = Graphics(bmp_image)

	# Fill the upper half of the image in red.
	redBrush = SolidBrush(Color.red)
	gr.fill_rectangle(redBrush, Rectangle(0, 0, bmp_image.width, bmp_image.height // 2))

	# Fill the lower half of the image in green.
	greenBrush = SolidBrush(Color.green)
	gr.fill_rectangle(greenBrush, Rectangle(0, bmp_image.height // 2, bmp_image.width, bmp_image.height // 2))

	# Save to BMP
	bmp_image.save(os.path.join(directory, "output.monochrome.96dpi.bmp"))

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

from aspose.imaging.fileformats.bmp import BmpImage

# Create a 32-bpp BMP image of 100 x 100 px.
with BmpImage(100, 100, 32, None) as bmp_image:
	print("FileFormat={0}, RawDataFormat={1}, HasAlpha={2}".format(bmp_image.file_format.name, bmp_image.raw_data_format, bmp_image.has_alpha))


# Create a 24-bpp BMP image of 100 x 100 px.
with BmpImage(100, 100, 24, None) as bmp_image:
	print("FileFormat={0}, RawDataFormat={1}, HasAlpha={2}".format(bmp_image.file_format.name, bmp_image.raw_data_format, bmp_image.has_alpha))

# Generally, BMP doesn't support alpha channel so the output will 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

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


from aspose.imaging import Color, ColorPalette, Graphics
from aspose.imaging.brushes import SolidBrush
from aspose.imaging.fileformats.bmp import BmpImage, BitmapCompression
from aspose.imaging.extensions import StreamExtensions as strm_ext

compressions = (BitmapCompression.RGB, BitmapCompression.RLE8)

paletterColors = (Color.red, Color.green)

# Create a monochrome palette which contains only red and green colors.
palette = ColorPalette.create_with_colors(paletterColors)

for compression in compressions:
	# Create a 8-bpp BMP image of 100 x 100 px.
	with BmpImage(100, 100, 8, palette, compression, 0.0, 0.0) as bmp_image:
		gr = Graphics(bmp_image)
		# Fill the entire image in red.
		red_brush = SolidBrush(Color.red)
		gr.fill_rectangle(red_brush, bmp_image.bounds)
		# Save the image to a memory stream to get the output image size.
		with strm_ext.create_memory_stream() as stream:
			bmp_image.save(stream)
			print("---------------------------------------------")
			print("The compression =", bmp_image.compression.name)
			print("The number of bits per pixel =", bmp_image.bits_per_pixel)
			print(f"The image dimensions = {bmp_image.width} x {bmp_image.height}")
			print("The raw line size =", bmp_image.raw_line_size)
			print("The output size in bytes =", stream.tell())

# The output looks 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 = 1178
# ---------------------------------------------
# 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

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


import os
import aspose.pycore as aspycore
from aspose.imaging import Image
from aspose.imaging.fileformats.bmp import BmpImage

directory = r"c:\temp"

with Image.load(os.path.join(directory, "sample.bmp")) as image:
	bmp_image = aspycore.as_of(image, BmpImage)
	# Get horizontal and vertical resolution of the BmpImage
	horizontal_resolution = bmp_image.horizontal_resolution
	vertical_resolution = bmp_image.vertical_resolution
	print("The horizontal resolution, in pixels per inch:", horizontal_resolution)
	print("The vertical resolution, in pixels per inch:", vertical_resolution)

	if (horizontal_resolution != 96.0 || vertical_resolution != 96.0)
	{
		# Use the set_resolution method for updating both resolution values in a single call.
		print("Set resolution values to 96 dpi")
		bmp_image.set_resolution(96.0, 96.0)
		print("The horizontal resolution, in pixels per inch:", bmp_image.horizontal_resolution);
		print("The vertical resolution, in pixels per inch:", bmp_image.vertical_resolution);
	}

	# The output may look like this:
	# The horizontal resolution, in pixels per inch: 0
	# The vertical resolution, in pixels per inch: 0
	# Set resolution values to 96 dpi
	# The horizontal resolution, in pixels per inch: 96.0
	# The vertical resolution, in pixels per inch: 96.0

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


import aspose.pycore as aspycore
from aspose.imaging import Image
from aspose.imaging.fileformats.bmp import BmpImage

with Image.load(r"c:\temp\sample.bmp") as image:
	bmp_image = aspycore.as_of(image, BmpImage)
	header = bmp_image.bitmap_info_header

	print("The number of palette colors that are required for displaying the bitmap:", header.bitmap_colors_important)
	print("The number of palette colors used in the bitmap:", header.bitmap_colors_used)
	print("The bitmap compression:", header.bitmap_compression)
	print("The bitmap height:", header.bitmap_height)
	print("The bitmap width:", header.bitmap_width)
	print("The bitmap raw data size in bytes:", header.bitmap_image_size)
	print("The number of planes:", header.bitmap_planes)
	print("The horizontal resolution of the bitmap, in pixels-per-meter:", header.bitmap_x_pels_per_meter)
	print("The vertical resolution of the bitmap, in pixels-per-meter:", header.bitmap_y_pels_per_meter)
	print("The number of bits per pixel:", header.bits_per_pixel)
	print("The extra bits masks:", header.extra_bit_masks)
	print("The header size in bytes:", header.header_size)

#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: 375
#The bitmap width: 500
#The bitmap raw data size in bytes: 562500
#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: 24
#The extra bits masks: 
#The header size in bytes: 40

Compress BMP image using DXT1 compression algorithm.

#cxFor:aspose.imaging.imageoptions.BmpOptions.compression

from aspose.imaging import Image
from aspose.imaging.imageoptions import BmpOptions
from aspose.imaging.fileformats.bmp import BitmapCompression

with Image.load("Tiger.bmp") as image:
	bmp_options = BmpOptions()
	bmp_options.compression = BitmapCompression.DXT1
	image.save("CompressedTiger.bmp", bmp_options)

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


from aspose.imaging import Image
from aspose.imaging.imageoptions import BmpOptions

with Image.load("CompressedTiger.bmp") as image:
	image.save("DecompressedTiger.bmp", BmpOptions())