RasterImage Class
Summary: Represents a raster image supporting raster graphics operations.
Module: aspose.imaging
Full Name: aspose.imaging.RasterImage
Inheritance: IObjectWithBounds, IRasterImageArgb32PixelLoader, IRasterImageRawDataLoader, IHasXmpData, IHasMetadata, Image
Properties
Name | Type | Access | Description |
---|---|---|---|
auto_adjust_palette | bool | r/w | Gets or sets a value indicating whether automatic adjust palette. |
background_color | Color | r/w | Gets or sets a value for the background color. |
bits_per_pixel | int | r | Gets the image bits per pixel count. |
bounds | Rectangle | r | Gets the image bounds. |
buffer_size_hint | int | r/w | Gets or sets the buffer size hint which is defined max allowed size for all internal buffers. |
container | Image | r | Gets the Image container. |
data_stream_container | StreamContainer | r | Gets the object’s data stream. |
disposed | bool | r | Gets a value indicating whether this instance is disposed. |
file_format | FileFormat | r | Gets a value of file format |
has_alpha | bool | r | Gets a value indicating whether this instance has alpha. |
has_background_color | bool | r/w | Gets or sets a value indicating whether image has background color. |
has_transparent_color | bool | r/w | Gets a value indicating whether image has transparent color. |
height | int | r | Gets the image height. |
horizontal_resolution | double | r/w | Gets or sets the horizontal resolution, in pixels per inch, of this RasterImage. |
image_opacity | float | r | Gets opacity of this image. |
interrupt_monitor | InterruptMonitor | r/w | Gets or sets the interrupt monitor. |
is_cached | bool | r | Gets a value indicating whether object’s data is cached currently and no data reading is required. |
is_raw_data_available | bool | r | Gets a value indicating whether raw data loading is available. |
palette | IColorPalette | r/w | Gets or sets the color palette. The color palette is not used when pixels are represented directly. |
premultiply_components | bool | r/w | Gets or sets a value indicating whether the image components must be premultiplied. |
raw_custom_color_converter | IColorConverter | r/w | Gets or sets the custom color converter |
raw_data_format | PixelDataFormat | r | Gets the raw data format. |
raw_data_settings | RawDataSettings | r | Gets the current raw data settings. Note when using these settings the data loads without conversion. |
raw_fallback_index | int | r/w | Gets or sets the fallback index to use when palette index is out of bounds |
raw_indexed_color_converter | IIndexedColorConverter | r/w | Gets or sets the indexed color converter |
raw_line_size | int | r | Gets the raw line size in bytes. |
size | Size | r | Gets the image size. |
transparent_color | Color | r/w | Gets the image transparent color. |
update_xmp_data | bool | r/w | Gets or sets a value indicating whether to update the XMP metadata. |
use_palette | bool | r | Gets a value indicating whether the image palette is used. |
use_raw_data | bool | r/w | Gets or sets a value indicating whether to use raw data loading when the raw data loading is available. |
vertical_resolution | double | r/w | Gets or sets the vertical resolution, in pixels per inch, of this RasterImage. |
width | int | r | Gets the image width. |
xmp_data | XmpPacketWrapper | r/w | Gets or sets the XMP metadata. |
Methods
Name | Description |
---|---|
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(files) | Creates the specified files. |
create(files, throw_exception_on_load_error) | Creates the specified files. |
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(multipage_create_options) | Creates the specified multipage create options. |
crop(left_shift, right_shift, top_shift, bottom_shift) | Crop image with shifts. |
crop(rectangle) | Crops the specified rectangle. |
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) | Gets the default options. |
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 path or URL. If filePath is a file path the method just opens the file. If filePath is an URL, the method downloads the file, stores it as a temporary one, and opens it. |
load(file_path, load_options) | Loads a new image from the specified file path or URL. If filePath is a file path the method just opens the file. If filePath is an URL, the method downloads the file, stores it as a temporary one, and opens it. |
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 packs. |
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 path or URL. If filePath is a file path the method just opens the file. If filePath is an URL, the method downloads the file, stores it as a temporary one, and opens it. |
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 with extended options. |
resize_by_settings(new_width, new_height, settings) | Resizes the image with extended options. |
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 the pixels. |
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) | Sets the resolution for this RasterImage. |
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. |
Property: has_alpha
Gets a value indicating whether this instance has alpha.
See also:
Example # 1: The following example loads raster images and prints information about raw da…
Example # 2: The following example shows how to extract information about raw data format …
Property: premultiply_components
Gets or sets a value indicating whether the image components must be premultiplied.
See also:
Example # 1: The following example creates a new raster image, saves the specified semi-tr…
Property: raw_data_format
Gets the raw data format.
See also:
Example # 1: The following example loads raster images and prints information about raw da…
Method: adjust_brightness(brightness)
adjust_brightness(brightness)
Adjust of a brightness for image.
Parameters:
Parameter | Type | Description |
---|---|---|
brightness | int | Brightness value. |
See also:
Example # 1: The following example performs brightness correction of an image.
Method: adjust_contrast(contrast)
adjust_contrast(contrast)
Image contrasting
Parameters:
Parameter | Type | Description |
---|---|---|
contrast | float | Contrast value (in range [-100; 100]) |
See also:
Example # 1: The following example performs contrast correction of an image.
Method: adjust_gamma(gamma)
adjust_gamma(gamma)
Gamma-correction of an image.
Parameters:
Parameter | Type | Description |
---|---|---|
gamma | float | Gamma for red, green and blue channels coefficient |
See also:
Example # 1: The following example performs gamma-correction of an image.
Method: adjust_gamma(gamma_red, gamma_green, gamma_blue)
adjust_gamma(gamma_red, gamma_green, gamma_blue)
Gamma-correction of an image.
Parameters:
Parameter | Type | Description |
---|---|---|
gamma_red | float | Gamma for red channel coefficient |
gamma_green | float | Gamma for green channel coefficient |
gamma_blue | float | Gamma for blue channel coefficient |
See also:
Example # 1: The following example performs gamma-correction of an image applying differen…
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:
Parameter | Type | Description |
---|---|---|
brightness_difference | double | The 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:
Parameter | Type | Description |
---|---|---|
brightness_difference | double | The brightness difference between pixel and the average of an s x s window of pixels centered around this pixel. |
window_size | int | The size of s x s window of pixels centered around this pixel |
See also:
Example # 1: The following example binarizes a raster image with Bradley’s adaptive thresh…
Method: binarize_fixed(threshold)
binarize_fixed(threshold)
Binarization of an image with predefined threshold
Parameters:
Parameter | Type | Description |
---|---|---|
threshold | byte | Threshold value. If corresponding gray value of a pixel is greater than threshold, a value of 255 will be assigned to it, 0 otherwise. |
See also:
Example # 1: The following example binarizes a raster image with the predefined threshold….
Method: blend(origin, overlay, overlay_alpha)
blend(origin, overlay, overlay_alpha)
Blends this image instance with the overlay image.
Parameters:
Parameter | Type | Description |
---|---|---|
origin | Point | The background image blending origin. |
overlay | RasterImage | The overlay image. |
overlay_alpha | byte | The 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:
Parameter | Type | Description |
---|---|---|
origin | Point | The background image blending origin. |
overlay | RasterImage | The overlay image. |
overlay_area | Rectangle | The overlay area. |
overlay_alpha | byte | The overlay alpha. |
Method: can_load(file_path) [static]
can_load(file_path)
Determines whether image can be loaded from the specified file path.
Parameters:
Parameter | Type | Description |
---|---|---|
file_path | string | The file path. |
Returns
Type | Description |
---|---|
bool |
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:
Parameter | Type | Description |
---|---|---|
file_path | string | The file path. |
load_options | LoadOptions | The load options. |
Returns
Type | Description |
---|---|
bool |
Method: can_load(stream) [static]
can_load(stream)
Determines whether image can be loaded from the specified stream.
Parameters:
Parameter | Type | Description |
---|---|---|
stream | _io.BufferedRandom | The stream to load from. |
Returns
Type | Description |
---|---|
bool |
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:
Parameter | Type | Description |
---|---|---|
stream | _io.BufferedRandom | The stream to load from. |
load_options | LoadOptions | The load options. |
Returns
Type | Description |
---|---|
bool |
Method: can_load_stream(stream) [static]
can_load_stream(stream)
Determines whether image can be loaded from the specified stream.
Parameters:
Parameter | Type | Description |
---|---|---|
stream | _io.BufferedRandom | The stream to load from. |
Returns
Type | Description |
---|---|
bool |
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:
Parameter | Type | Description |
---|---|---|
stream | _io.BufferedRandom | The stream to load from. |
load_options | LoadOptions | The load options. |
Returns
Type | Description |
---|---|
bool |
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:
Parameter | Type | Description |
---|---|---|
file_path | string | The file path. |
load_options | LoadOptions | The load options. |
Returns
Type | Description |
---|---|
bool |
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:
Parameter | Type | Description |
---|---|---|
options | ImageOptionsBase | The save options to use. |
Returns
Type | Description |
---|---|
bool |
Method: create(files) [static]
create(files)
Creates the specified files.
Parameters:
Parameter | Type | Description |
---|---|---|
files | string | The files. |
Returns
Type | Description |
---|---|
Image | The multipage image |
Method: create(files, throw_exception_on_load_error) [static]
create(files, throw_exception_on_load_error)
Creates the specified files.
Parameters:
Parameter | Type | Description |
---|---|---|
files | string | The files. |
throw_exception_on_load_error | bool | if set to |
Returns
Type | Description |
---|---|
Image | The multipage image |
Method: create(image_options, width, height) [static]
create(image_options, width, height)
Creates a new image using the specified create options.
Parameters:
Parameter | Type | Description |
---|---|---|
image_options | ImageOptionsBase | The image options. |
width | int | The width. |
height | int | The height. |
Returns
Type | Description |
---|---|
Image | The newly created image. |
Method: create(images) [static]
create(images)
Creates a new image using the specified images as pages
Parameters:
Parameter | Type | Description |
---|---|---|
images | Image[] | The images. |
Returns
Type | Description |
---|---|
Image | The Image as IMultipageImage |
Method: create(images, dispose_images) [static]
create(images, dispose_images)
Creates a new image the specified images as pages.
Parameters:
Parameter | Type | Description |
---|---|---|
images | Image[] | The images. |
dispose_images | bool | if set to |
Returns
Type | Description |
---|---|
Image | The Image as IMultipageImage |
Method: create(multipage_create_options) [static]
create(multipage_create_options)
Creates the specified multipage create options.
Parameters:
Parameter | Type | Description |
---|---|---|
multipage_create_options | MultipageCreateOptions | The multipage create options. |
Returns
Type | Description |
---|---|
Image | The multipage image |
Method: crop(left_shift, right_shift, top_shift, bottom_shift)
crop(left_shift, right_shift, top_shift, bottom_shift)
Crop image with shifts.
Parameters:
Parameter | Type | Description |
---|---|---|
left_shift | int | The left shift. |
right_shift | int | The right shift. |
top_shift | int | The top shift. |
bottom_shift | int | The bottom shift. |
See also:
Example # 1: The following example crops a raster image. The cropping area is specified vi…
Method: crop(rectangle)
crop(rectangle)
Crops the specified rectangle.
Parameters:
Parameter | Type | Description |
---|---|---|
rectangle | Rectangle | The rectangle. |
See also:
Example # 1: The following example crops a raster image. The cropping area is be specified…
Method: dither(dithering_method, bits_count)
dither(dithering_method, bits_count)
Performs dithering on the current image.
Parameters:
Parameter | Type | Description |
---|---|---|
dithering_method | DitheringMethod | The dithering method. |
bits_count | int | The final bits count for dithering. |
See also:
Example # 1: The following example loads a raster image and performs threshold and Floyd d…
Method: dither(dithering_method, bits_count, custom_palette)
dither(dithering_method, bits_count, custom_palette)
Performs dithering on the current image.
Parameters:
Parameter | Type | Description |
---|---|---|
dithering_method | DitheringMethod | The dithering method. |
bits_count | int | The final bits count for dithering. |
custom_palette | IColorPalette | The custom palette for dithering. |
Method: filter(rectangle, options)
filter(rectangle, options)
Filters the specified rectangle.
Parameters:
Parameter | Type | Description |
---|---|---|
rectangle | Rectangle | The rectangle. |
options | FilterOptionsBase | The options. |
See also:
Example # 1: The following example applies various types of filters to a raster image.
Method: get_argb_32_pixel(x, y)
get_argb_32_pixel(x, y)
Gets an image 32-bit ARGB pixel.
Parameters:
Parameter | Type | Description |
---|---|---|
x | int | The pixel x location. |
y | int | The pixel y location. |
Returns
Type | Description |
---|---|
int | The 32-bit ARGB pixel for the specified location. |
See also:
Example # 1: The following example shows how image caching affects performance. In general…
Example # 2: The following example loads a raster image and obtains the color of an arbitr…
Method: get_default_argb_32_pixels(rectangle)
get_default_argb_32_pixels(rectangle)
Gets the default 32-bit ARGB pixels array.
Parameters:
Parameter | Type | Description |
---|---|---|
rectangle | Rectangle | The rectangle to get pixels for. |
Returns
Type | Description |
---|---|
int | The default pixels array. |
Method: get_default_options(args)
get_default_options(args)
Gets the default options.
Parameters:
Parameter | Type | Description |
---|---|---|
args | object | The arguments. |
Returns
Type | Description |
---|---|
ImageOptionsBase | Default 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:
Parameter | Type | Description |
---|---|---|
rectangle | Rectangle | The rectangle to get pixels for. |
partial_pixel_loader | IPartialArgb32PixelLoader | The 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:
Parameter | Type | Description |
---|---|---|
rectangle | Rectangle | The rectangle to get pixels for. |
partial_raw_data_loader | IPartialRawDataLoader | The partial raw data loader. |
raw_data_settings | RawDataSettings | The 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:
Parameter | Type | Description |
---|---|---|
rectangle | Rectangle | The rectangle to get raw data for. |
raw_data_settings | RawDataSettings | The raw data settings. |
Returns
Type | Description |
---|---|
byte | The default raw data array. |
Method: get_file_format(file_path) [static]
get_file_format(file_path)
Gets the file format.
Parameters:
Parameter | Type | Description |
---|---|---|
file_path | string | The file path. |
Returns
Type | Description |
---|---|
FileFormat | The determined file format. |
Method: get_file_format(stream) [static]
get_file_format(stream)
Gets the file format.
Parameters:
Parameter | Type | Description |
---|---|---|
stream | _io.BufferedRandom | The stream. |
Returns
Type | Description |
---|---|
FileFormat | The determined file format. |
Method: get_file_format_of_stream(stream) [static]
get_file_format_of_stream(stream)
Gets the file format.
Parameters:
Parameter | Type | Description |
---|---|---|
stream | _io.BufferedRandom | The stream. |
Returns
Type | Description |
---|---|
FileFormat | The 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:
Parameter | Type | Description |
---|---|---|
rectangle | Rectangle | The rectangle to get fitting rectangle for. |
pixels | int | The 32-bit ARGB pixels. |
width | int | The object width. |
height | int | The object height. |
Returns
Type | Description |
---|---|
Rectangle | The 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:
Parameter | Type | Description |
---|---|---|
rectangle | Rectangle | The rectangle to get fitting rectangle for. |
width | int | The object width. |
height | int | The object height. |
Returns
Type | Description |
---|---|
Rectangle | The 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:
Parameter | Type | Description |
---|---|---|
use_default | bool | if set to |
Returns
Type | Description |
---|---|
datetime | The 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
Type | Description |
---|---|
ImageOptionsBase | The options based on the original file settings. |
Method: get_pixel(x, y)
get_pixel(x, y)
Gets an image pixel.
Parameters:
Parameter | Type | Description |
---|---|---|
x | int | The pixel x location. |
y | int | The pixel y location. |
Returns
Type | Description |
---|---|
Color | The pixel color for the specified location. |
See also:
Example # 1: The following example loads a raster image and obtains the color of an arbitr…
Method: get_proportional_height(width, height, new_width) [static]
get_proportional_height(width, height, new_width)
Gets a proportional height.
Parameters:
Parameter | Type | Description |
---|---|---|
width | int | The width. |
height | int | The height. |
new_width | int | The new width. |
Returns
Type | Description |
---|---|
int | The proportional height. |
Method: get_proportional_width(width, height, new_height) [static]
get_proportional_width(width, height, new_height)
Gets a proportional width.
Parameters:
Parameter | Type | Description |
---|---|---|
width | int | The width. |
height | int | The height. |
new_height | int | The new height. |
Returns
Type | Description |
---|---|
int | The 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:
Parameter | Type | Description |
---|---|---|
image_options | ImageOptionsBase | The image options. |
clipping_rectangle | Rectangle | The clipping rectangle. |
page_number | int[] | The page number. |
Returns
Type | Description |
---|---|
_io.BufferedRandom | The 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
Type | Description |
---|---|
float | The skew angle, in degrees. |
Method: load(file_path) [static]
load(file_path)
Loads a new image from the specified file path or URL.
If filePath is a file path the method just opens the file.
If filePath is an URL, the method downloads the file, stores it as a temporary one, and opens it.
Parameters:
Parameter | Type | Description |
---|---|---|
file_path | string | The file path or URL to load image from. |
Returns
Type | Description |
---|---|
Image | The loaded image. |
Method: load(file_path, load_options) [static]
load(file_path, load_options)
Loads a new image from the specified file path or URL.
If filePath is a file path the method just opens the file.
If filePath is an URL, the method downloads the file, stores it as a temporary one, and opens it.
Parameters:
Parameter | Type | Description |
---|---|---|
file_path | string | The file path or URL to load image from. |
load_options | LoadOptions | The load options. |
Returns
Type | Description |
---|---|
Image | The loaded image. |
Method: load(stream) [static]
load(stream)
Loads a new image from the specified stream.
Parameters:
Parameter | Type | Description |
---|---|---|
stream | _io.BufferedRandom | The stream to load image from. |
Returns
Type | Description |
---|---|
Image | The loaded image. |
Method: load(stream, load_options) [static]
load(stream, load_options)
Loads a new image from the specified stream.
Parameters:
Parameter | Type | Description |
---|---|---|
stream | _io.BufferedRandom | The stream to load image from. |
load_options | LoadOptions | The load options. |
Returns
Type | Description |
---|---|
Image | The loaded image. |
Method: load_argb_32_pixels(rectangle)
load_argb_32_pixels(rectangle)
Loads 32-bit ARGB pixels.
Parameters:
Parameter | Type | Description |
---|---|---|
rectangle | Rectangle | The rectangle to load pixels from. |
Returns
Type | Description |
---|---|
int | The loaded 32-bit ARGB pixels array. |
See also:
Example # 1: The following example shows how to load and process pixels of a raster image….
Method: load_argb_64_pixels(rectangle)
load_argb_64_pixels(rectangle)
Loads 64-bit ARGB pixels.
Parameters:
Parameter | Type | Description |
---|---|---|
rectangle | Rectangle | The rectangle to load pixels from. |
Returns
Type | Description |
---|---|
long | The loaded 64-bit ARGB pixels array. |
See also:
Example # 1: The following example shows how to load and process pixels of a raster image….
Method: load_cmyk_32_pixels(rectangle)
load_cmyk_32_pixels(rectangle)
Loads pixels in CMYK format.
Parameters:
Parameter | Type | Description |
---|---|---|
rectangle | Rectangle | The rectangle to load pixels from. |
Returns
Type | Description |
---|---|
int | The 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:
Parameter | Type | Description |
---|---|---|
rectangle | Rectangle | The rectangle to load pixels from. |
Returns
Type | Description |
---|---|
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 packs.
Parameters:
Parameter | Type | Description |
---|---|---|
rectangle | Rectangle | The desired rectangle. |
partial_pixel_loader | IPartialArgb32PixelLoader | The 32-bit ARGB 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:
Parameter | Type | Description |
---|---|---|
rectangle | Rectangle | The desired rectangle. |
partial_pixel_loader | IPartialArgb64PixelLoader | The 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:
Parameter | Type | Description |
---|---|---|
desired_rectangle | Rectangle | The desired rectangle. |
pixel_loader | IPartialPixelLoader | The pixel loader. |
Method: load_pixels(rectangle)
load_pixels(rectangle)
Loads pixels.
Parameters:
Parameter | Type | Description |
---|---|---|
rectangle | Rectangle | The rectangle to load pixels from. |
Returns
Type | Description |
---|---|
Color[] | The loaded pixels array. |
See also:
Example # 1: This example shows how to load a pixels information in an array of Color, man…
Example # 2: The following example shows how to load and process pixels of a raster image….
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:
Parameter | Type | Description |
---|---|---|
rectangle | Rectangle | The rectangle to load raw data from. |
dest_image_bounds | Rectangle | The dest image bounds. |
raw_data_settings | RawDataSettings | The 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_loader | IPartialRawDataLoader | The 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:
Parameter | Type | Description |
---|---|---|
rectangle | Rectangle | The rectangle to load raw data from. |
raw_data_settings | RawDataSettings | The 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_loader | IPartialRawDataLoader | The raw data loader. |
Method: load_stream(stream) [static]
load_stream(stream)
Loads a new image from the specified stream.
Parameters:
Parameter | Type | Description |
---|---|---|
stream | _io.BufferedRandom | The stream to load image from. |
Returns
Type | Description |
---|---|
Image | The 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:
Parameter | Type | Description |
---|---|---|
stream | _io.BufferedRandom | The stream to load image from. |
load_options | LoadOptions | The load options. |
Returns
Type | Description |
---|---|
Image | The 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 path or URL.
If filePath is a file path the method just opens the file.
If filePath is an URL, the method downloads the file, stores it as a temporary one, and opens it.
Parameters:
Parameter | Type | Description |
---|---|---|
file_path | string | The file path or URL to load image from. |
load_options | LoadOptions | The load options. |
Returns
Type | Description |
---|---|
Image | The 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:
Parameter | Type | Description |
---|---|---|
resize_proportionally | bool | if set to |
background_color | Color | Color 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:
Parameter | Type | Description |
---|---|---|
scan_line_index | int | Zero based index of the scan line. |
Returns
Type | Description |
---|---|
int | The 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:
Parameter | Type | Description |
---|---|---|
scan_line_index | int | Zero based index of the scan line. |
Returns
Type | Description |
---|---|
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:
Parameter | Type | Description |
---|---|---|
old_color_argb | int | Old color ARGB value to be replaced. |
old_color_diff | byte | Allowed difference in old color to be able to widen replaced color tone. |
new_color_argb | int | New 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:
Parameter | Type | Description |
---|---|---|
old_color | Color | Old color to be replaced. |
old_color_diff | byte | Allowed difference in old color to be able to widen replaced color tone. |
new_color | Color | New 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:
Parameter | Type | Description |
---|---|---|
old_color_argb | int | Old color ARGB value to be replaced. |
old_color_diff | byte | Allowed difference in old color to be able to widen replaced color tone. |
new_color_argb | int | New 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:
Parameter | Type | Description |
---|---|---|
new_color | Color | New 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:
Parameter | Type | Description |
---|---|---|
new_color_argb | int | New 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:
Parameter | Type | Description |
---|---|---|
new_width | int | The new width. |
new_height | int | The new height. |
Method: resize(new_width, new_height, resize_type)
resize(new_width, new_height, resize_type)
Resizes the image.
Parameters:
Parameter | Type | Description |
---|---|---|
new_width | int | The new width. |
new_height | int | The new height. |
resize_type | ResizeType | The resize type. |
See also:
Example # 1: This example loads a raster image and resizes it using various resizing methods.
Method: resize(new_width, new_height, settings)
resize(new_width, new_height, settings)
Resizes the image with extended options.
Parameters:
Parameter | Type | Description |
---|---|---|
new_width | int | The new width. |
new_height | int | The new height. |
settings | ImageResizeSettings | The resize settings. |
See also:
Example # 1: This example loads a raster image and resizes it using various resizing setti…
Method: resize_by_settings(new_width, new_height, settings)
resize_by_settings(new_width, new_height, settings)
Resizes the image with extended options.
Parameters:
Parameter | Type | Description |
---|---|---|
new_width | int | The new width. |
new_height | int | The new height. |
settings | ImageResizeSettings | The 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:
Parameter | Type | Description |
---|---|---|
new_width | int | The new width. |
new_height | int | The new height. |
resize_type | ResizeType | The 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:
Parameter | Type | Description |
---|---|---|
new_height | int | The new height. |
Method: resize_height_proportionally(new_height, resize_type)
resize_height_proportionally(new_height, resize_type)
Resizes the height proportionally.
Parameters:
Parameter | Type | Description |
---|---|---|
new_height | int | The new height. |
resize_type | ResizeType | Type of the resize. |
Method: resize_height_proportionally(new_height, settings)
resize_height_proportionally(new_height, settings)
Resizes the height proportionally.
Parameters:
Parameter | Type | Description |
---|---|---|
new_height | int | The new height. |
settings | ImageResizeSettings | The image resize settings. |
Method: resize_height_proportionally_settings(new_height, settings)
resize_height_proportionally_settings(new_height, settings)
Resizes the height proportionally.
Parameters:
Parameter | Type | Description |
---|---|---|
new_height | int | The new height. |
settings | ImageResizeSettings | The 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:
Parameter | Type | Description |
---|---|---|
new_width | int | The new width. |
Method: resize_width_proportionally(new_width, resize_type)
resize_width_proportionally(new_width, resize_type)
Resizes the width proportionally.
Parameters:
Parameter | Type | Description |
---|---|---|
new_width | int | The new width. |
resize_type | ResizeType | Type of the resize. |
Method: resize_width_proportionally(new_width, settings)
resize_width_proportionally(new_width, settings)
Resizes the width proportionally.
Parameters:
Parameter | Type | Description |
---|---|---|
new_width | int | The new width. |
settings | ImageResizeSettings | The image resize settings. |
Method: resize_width_proportionally_settings(new_width, settings)
resize_width_proportionally_settings(new_width, settings)
Resizes the width proportionally.
Parameters:
Parameter | Type | Description |
---|---|---|
new_width | int | The new width. |
settings | ImageResizeSettings | The image resize settings. |
Method: rotate(angle)
rotate(angle)
Rotate image around the center.
Parameters:
Parameter | Type | Description |
---|---|---|
angle | float | The 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:
Parameter | Type | Description |
---|---|---|
angle | float | The rotate angle in degrees. Positive values will rotate clockwise. |
resize_proportionally | bool | if set to |
background_color | Color | Color of the background. |
Method: rotate_flip(rotate_flip_type)
rotate_flip(rotate_flip_type)
Rotates, flips, or rotates and flips the image.
Parameters:
Parameter | Type | Description |
---|---|---|
rotate_flip_type | RotateFlipType | Type of the rotate flip. |
Method: save(file_path)
save(file_path)
Saves the image to the specified file location.
Parameters:
Parameter | Type | Description |
---|---|---|
file_path | string | The 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:
Parameter | Type | Description |
---|---|---|
file_path | string | The file path. |
options | ImageOptionsBase | The 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:
Parameter | Type | Description |
---|---|---|
file_path | string | The file path. |
options | ImageOptionsBase | The options. |
bounds_rectangle | Rectangle | The 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:
Parameter | Type | Description |
---|---|---|
file_path | string | The file path to save the object’s data to. |
over_write | bool | if set to |
Method: save(stream)
save(stream)
Saves the object’s data to the specified stream.
Parameters:
Parameter | Type | Description |
---|---|---|
stream | _io.BufferedRandom | The 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:
Parameter | Type | Description |
---|---|---|
stream | _io.BufferedRandom | The stream to save the image’s data to. |
options_base | ImageOptionsBase | The 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:
Parameter | Type | Description |
---|---|---|
stream | _io.BufferedRandom | The stream to save the image’s data to. |
options_base | ImageOptionsBase | The save options. |
bounds_rectangle | Rectangle | The 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:
Parameter | Type | Description |
---|---|---|
rectangle | Rectangle | The rectangle to save pixels to. |
pixels | int | The 32-bit ARGB pixels array. |
See also:
Example # 1: The following example fills the central area of a raster image with black pix…
Method: save_cmyk_32_pixels(rectangle, pixels)
save_cmyk_32_pixels(rectangle, pixels)
Saves the pixels.
Parameters:
Parameter | Type | Description |
---|---|---|
rectangle | Rectangle | The rectangle to save pixels to. |
pixels | int | The CMYK pixels presented as the 32-bit integer values. |
See also:
Example # 1: The following example fills the central area of a raster image with black pix…
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:
Parameter | Type | Description |
---|---|---|
rectangle | Rectangle | The rectangle to save pixels to. |
pixels | CmykColor[] | The CMYK pixels array. |
Method: save_pixels(rectangle, pixels)
save_pixels(rectangle, pixels)
Saves the pixels.
Parameters:
Parameter | Type | Description |
---|---|---|
rectangle | Rectangle | The rectangle to save pixels to. |
pixels | Color[] | The pixels array. |
See also:
Example # 1: This example shows how to load a pixels information in an array of Color, man…
Example # 2: The following example fills the central area of a raster image with black pix…
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:
Parameter | Type | Description |
---|---|---|
data | byte | The raw data. |
data_offset | int | The starting raw data offset. |
rectangle | Rectangle | The raw data rectangle. |
raw_data_settings | RawDataSettings | The 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:
Parameter | Type | Description |
---|---|---|
stream | _io.BufferedRandom | The 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:
Parameter | Type | Description |
---|---|---|
stream | _io.BufferedRandom | The stream to save the image’s data to. |
options_base | ImageOptionsBase | The 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:
Parameter | Type | Description |
---|---|---|
stream | _io.BufferedRandom | The stream to save the image’s data to. |
options_base | ImageOptionsBase | The save options. |
bounds_rectangle | Rectangle | The 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:
Parameter | Type | Description |
---|---|---|
file_path | string | The file path. |
options | ImageOptionsBase | The 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:
Parameter | Type | Description |
---|---|---|
file_path | string | The file path. |
options | ImageOptionsBase | The options. |
bounds_rectangle | Rectangle | The 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:
Parameter | Type | Description |
---|---|---|
x | int | The pixel x location. |
y | int | The pixel y location. |
argb_32_color | int | The 32-bit ARGB pixel for the specified position. |
See also:
Example # 1: The following example loads a raster image, and sets the color of an arbitrar…
Method: set_palette(palette, update_colors)
set_palette(palette, update_colors)
Sets the image palette.
Parameters:
Parameter | Type | Description |
---|---|---|
palette | IColorPalette | The palette to set. |
update_colors | bool | if set to |
Method: set_pixel(x, y, color)
set_pixel(x, y, color)
Sets an image pixel for the specified position.
Parameters:
Parameter | Type | Description |
---|---|---|
x | int | The pixel x location. |
y | int | The pixel y location. |
color | Color | The pixel color for the specified position. |
See also:
Example # 1: The following example loads a raster image, and sets the color of an arbitrar…
Method: set_resolution(dpi_x, dpi_y)
set_resolution(dpi_x, dpi_y)
Sets the resolution for this RasterImage.
Parameters:
Parameter | Type | Description |
---|---|---|
dpi_x | double | The horizontal resolution, in dots per inch, of the RasterImage. |
dpi_y | double | The vertical resolution, in dots per inch, of the RasterImage. |
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:
Parameter | Type | Description |
---|---|---|
scan_line_index | int | Zero based index of the scan line. |
argb_32_pixels | int | The 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:
Parameter | Type | Description |
---|---|---|
scan_line_index | int | Zero based index of the scan line. |
pixels | Color[] | The pixel colors array to write. |
Examples
This example shows how to load a pixels information in an array of Color, manipulates the array and set it back to the image. To perform these operations, this example creates a new Image file (in GIF format) using MemoryStream object.
from aspose.pycore import as_of
from aspose.imaging import Image, RasterImage, Color
from aspose.imaging.externsions import StreamExtensions as strm_ext
from aspose.imaging.imageoptions import GifOptions
from aspose.imaging.sources import StreamSource
# Create an instance of MemoryStream
with strm_ext.create_memory_stream() as stream:
#Create an instance of GifOptions and set its various properties including the Source property
with GifOptions() as gifOptions:
gifOptions.source = StreamSource(stream)
# Create an instance of Image
with as_of(Image.create(gifOptions, 500, 500), RasterImage) as image:
# Get the pixels of image by specifying the area as image boundary
pixels = image.load_pixels(image.bounds)
yellow_color = Color.yellow
blue_color = Color.blue
#Loop over the Array and sets color of alternative indexed pixel
for index in range(pixel.length):
if index % 2 == 0:
#Set the indexed pixel color to yellow
pixels[index] = yellow_color
else:
#Set the indexed pixel color to blue
pixels[index] = blue_color
#Apply the pixel changes to the image
image.save_pixels(image.bounds, pixels)
# save all changes.
image.save()
# Write MemoryStream to File
stream.seek(0)
with open(r"C:\temp\output.gif", "wb") as fileStream:
fileStream.write(stream.read())
}
The following example shows how image caching affects performance. In general case, reading cached data is performed faster than reading non-cached data.
from aspose.imaging import Image, Rectangle
from aspose.imaging.imageoptions import PngOptions
from os.path import join as path_join
directory = r"c:\temp"
# Load an image from a PNG file.
with Image.load(path_join(directory, "sample.png")) as image:
# Cache all pixel data so that no additional data loading will be performed from the underlying data stream
image.cache_daata()
start_time = timedelta()
# Reading all pixels is pretty fast.
rasterImage = as_of(image, RasterImage)
for y in range(image.height):
for x in range(image.width):
color = rasterImage.get_argb_32_pixel(x, y)
end_time = timedelta()
time = (end_time.microseconds - start_time.microseconds) / 1000000
print(f"Reading all cached pixels took {time} ms.")
# Load an image from a PNG file
with Image.load(path_join(directory, "sample.png")) as image:
start_time = timedelta()
# Reading all pixels is not as fast as when caching
rasterImage = as_of(image, RasterImage)
for y in range(image.height):
for x in range(image.width):
color = rasterImage.get_argb_32_pixel(x, y)
end_time = timedelta()
time = (end_time.microseconds - start_time.microseconds) / 1000000
print(f"Reading all pixels without preliminary caching took {time} ms.")
# The output may look like this:
# Reading all cached pixels took 1500 ms.
# Reading all pixels without preliminary caching took 150000 ms.
The following example creates a new raster image, saves the specified semi-transparent pixels, then loads those pixels and gets final colors in the premultiplied form.
from aspose.pycore import as_of
from aspose.imaging import Image, RasterImage, Color
from aspose.imaging.imageoptions import PngOptions
from aspose.imaging.sources import StreamSource
from aspose.imaging.fileformats.png import PngColorType
image_width = 3
image_height = 2
colors = [
Color.from_argb(127, 255, 0, 0),
Color.from_argb(127, 0, 255, 0),
Color.from_argb(127, 0, 0, 255),
Color.from_argb(127, 255, 255, 0),
Color.from_argb(127, 255, 0, 255),
Color.from_argb(127, 0, 255, 255)
]
create_options = PngOptions()
create_options.source = StreamSource()
create_options.color_type = PngColorType.TRUECOLOR_WITH_ALPHA
with Image.create(create_options, image_width, image_height) as image:
raster_image = as_of(image, RasterImage)
# Save pixels for the whole image.
raster_image.save_pixels(raster_image.bounds, colors)
# The pixels are stored in the original image in the non-premultiplied form.
# Need to specify the corresponding option explicitly to obtain premultiplied color components.
# The premultiplied color components are calculated by the formulas:
# red = original_red * alpha / 255;
# green = original_green * alpha / 255;
# blue = original_blue * alpha / 255;
raster_image.premultiply_components = True
premultiplied_colors = raster_image.load_pixels(raster_image.bounds)
for i in range(len(colors)):
print(f"Original color: {colors[i]}")
print(f"Premultiplied color: {premultiplied_colors[i]}")
The following example loads raster images and prints information about raw data format and alpha channel.
from aspose.pycore import as_of
from aspose.imaging import Image, RasterImage
# The image files to load.
fileNames = (r"c:\temp\sample.bmp", r"c:\temp\alpha.png")
for fileName in fileNames:
with Image.load(fileName) as image:
raster_image = as_of(image, RasterImage)
print(f"ImageFile={fileName}, FileFormat={raster_image.raw_data_format}, HasAlpha={raster_image.has_alpha}")
# The output may look like this:
# ImageFile=c:\temp\sample.bmp, FileFormat=Rgb24Bpp, used channels: 8,8,8, HasAlpha=False
# ImageFile=c:\temp\alpha.png, FileFormat=RGBA32Bpp, used channels: 8,8,8,8, HasAlpha=True
The following example loads a raster image and performs threshold and Floyd dithering using different palette depth.
from aspose.pycore import as_of
from aspose.imaging import Image, RasterImage, DitheringMethod
from os.path import join as join_path
directory = r"c:\temp"
with Image.load(join_path(directory, "sample.png")) as image:
rasterImage = as_of(image, RasterImage)
# Perform threshold dithering using 4-bit color palette which contains 16 colors.
# The more bits specified the higher quality and the bigger size of the output image.
# Note that only 1-bit, 4-bit and 8-bit palettes are supported at the moment.
rasterImage.dither(DitheringMethod.THRESHOLD_DITHERING, 4)
rasterImage.save(join_path(directory, "sample.ThresholdDithering4.png"))
with Image.load(join_path(directory, "sample.png")) as image:
rasterImage = as_of(image, RasterImage)
# Perform Floyd dithering using 1-bit color palette which contains only 2 colors - black and white.
# The more bits specified the higher quality and the bigger size of the output image.
# Note that only 1-bit, 4-bit and 8-bit palettes are supported at the moment.
rasterImage.dither(DitheringMethod.FLOYD_STEINBERG_DITHERING, 1)
rasterImage.save(join_path(directory, "sample.FloydSteinbergDithering1.png"))
The following example loads a raster image and obtains the color of an arbitrary pixel represented as a 32-bit integer value.
from aspose.pycore import as_of
from aspose.imaging import Image, RasterImage
with Image.load("sample.png") as image:
rasterImage = as_of(image, RasterImage)
# Get an integer representation of the color of the top-left pixel of the image.
color = rasterImage.get_argb_32_pixel(0, 0)
# To obtain the values of the individual color components, shift the color value by a corresponding number of bits
alpha = (color >> 24) & 0xff
red = (color >> 16) & 0xff
green = (color >> 8) & 0xff
blue = (color >> 0) & 0xff
print(f"The color of the pixel(0,0) is A={alpha},R={red},G={green},B={blue}")
The following example loads a raster image and obtains the color of an arbitrary pixel.
from aspose.pycore import as_of
from aspose.imaging import Image, RasterImage
with Image.load("sample.png") as image:
rasterImage = as_of(image, RasterImage)
# Get the color of the top-left pixel of the image.
color = rasterImage.get_pixel(0, 0)
# Obtain the values of the individual color components
alpha = color.a
red = color.r
green = color.g
blue = color.b
print(f"The color of the pixel(0,0) is A={alpha},R={red},G={green},B={blue}")
The following example loads a raster image, and sets the color of an arbitrary pixel.
from aspose.pycore import as_of
from aspose.imaging import Image, RasterImage, Color
with Image.load("sample.png") as image:
rasterImage = as_of(image, RasterImage)
# Sets the color of the top-left pixel.
rasterImage.set_argb_32_pixel(0, 0, Color.aqua.to_argb())
# Another way is to pass an instance of the aspose.imaging.Color directly
rasterImage.set_pixel(0, 0, Color.aqua)
The following example shows how to load and process pixels of a raster image. The pixels are represented as 32-bit integer values. For example, consider a problem of counting of fully transparent pixels of an image.
from aspose.pycore import as_of
from aspose.imaging import Image, RasterImage
with Image.load("alpha.png") as image:
rasterImage = as_of(image, RasterImage)
# Load pixels for the whole image. Any rectangular part of the image can be specified as a parameter of the aspose.imaging.RasterImage.load_argb_32_pixels(rectangle) method.
pixels = rasterImage.load_argb_32_pixels(rasterImage.bounds)
count = 0
for pixel in pixels:
alpha = (pixel >> 24) & 0xff
if alpha == 0:
count += 1
print(f"The number of fully transparent pixels is {count}")
print(f"The total number of pixels is {image.width * image.height}")
The following example shows how to load and process pixels of a raster image. The pixels are represented as 64-bit integer values. For example, consider a problem of counting of fully transparent pixels of an image.
from aspose.pycore import as_of
from aspose.imaging import Image, RasterImage
with Image.load("16rgba.png") as image:
rasterImage = as_of(image, RasterImage)
# Load pixels for the whole image. Any rectangular part of the image can be specified as a parameter of the aspose.imaging.RasterImage.load_argb_64_pixels method.
# Note that the image itself must have 16 bits per sample, because aspose.imaging.RasterImage.load_argb_64_pixels doesn't work with 8 bit per sample.
# In order to work with 8 bits per sample please use the good old aspose.imaging.RasterImage.load_argb_64_pixels method.
pixels = rasterImage.load_argb_64_pixels(rasterImage.bounds)
count = 0
for pixel in pixels:
# Note that all color components including alpha are represented by 16-bit values, so their allowed values are in the range [0, 63535].
alpha = (pixel >> 48) & 0xffff
if alpha == 0:
count += 1
print(f"The number of fully transparent pixels is {count}")
print(f"The total number of pixels is {image.width * image.height}")
The following example shows how to load and process pixels of a raster image. For example, consider a problem of counting of fully transparent pixels of an image.
from aspose.pycore import as_of
from aspose.imaging import Image, RasterImage
with Image.load("alpha.png") as image:
rasterImage = as_of(image, RasterImage)
# Load pixels for the whole image. Any rectangular part of the image can be specified as a parameter of the aspose.imaging.RasterImage.load_pixels method.
pixels = rasterImage.load_pixels(rasterImage.bounds)
count = 0
for pixel in pixels:
if pixel.a == 0:
count += 1
print(f"The number of fully transparent pixels is {count}")
print(f"The total number of pixels is {image.width * image.height}")
The following example fills the central area of a raster image with black pixels using the aspose.imaging.RasterImage.save_argb_32_pixels method.
from aspose.pycore import as_of
from aspose.imaging import Image, RasterImage, Rectangle, Color
from os.path import join as join_path
directory = r"c:\temp"
with Image.load(join_path(directory, "sample.png")) as image:
rasterImage = as_of(image, RasterImage)
# The black square
pixel_count = ((rasterImage.width // 2) * (rasterImage.height // 2))
black_color = Color.black.to_argb()
pixels = [black_color] * pixel_count
# Draw the black square at the center of the image.
area = Rectangle(rasterImage.width // 4, rasterImage.height // 4, rasterImage.width // 2, rasterImage.height // 2)
rasterImage.save_argb_32_pixels(area, pixels)
rasterImage.save(join_path(directory, "sample.SaveArgb32Pixels.png"))
The following example fills the central area of a raster image with black pixels using the aspose.imaging.RasterImage.save_pixels method.
from aspose.pycore import as_of
from aspose.imaging import Image, RasterImage, Rectangle, Color
from os.path import join as join_path
directory = r"c:\temp"
with Image.load(join_path(directory, "sample.png")) as image:
rasterImage = as_of(image, RasterImage)
# The black square
pixel_count = ((rasterImage.width // 2) * (rasterImage.height // 2))
black_color = Color.black
pixels = [black_color] * pixel_count
# Draw the black square at the center of the image.
area = Rectangle(rasterImage.width // 4, rasterImage.height // 4, rasterImage.width // 2, rasterImage.height // 2)
rasterImage.save_pixels(area, pixels)
rasterImage.save(join_path(directory, "sample.SavePixels.png"))
The following example fills the central area of a raster image with black pixels using the aspose.imaging.RasterImage.save_cmyk_32_pixels method.
from aspose.pycore import as_of
from aspose.imaging import Image, RasterImage, Rectangle, Color, CmykColorHelper
from os.path import join as join_path
directory = r"c:\temp"
with Image.load(join_path(directory, "sample.png")) as image:
rasterImage = as_of(image, RasterImage)
# Get an integer representation of black in the CMYK color space.
blackCmyk = CmykColorHelper.to_cmyk(Color.black)
# The black square.
pixel_count = (rasterImage.width // 2) * (rasterImage.height // 2)
pixels = [blackCmyk] * pixel_count
# Draw the black square at the center of the image.
area = Rectangle(rasterImage.width // 4, rasterImage.height // 4, rasterImage.width // 2, rasterImage.height // 2)
rasterImage.save_cmyk_32_pixels(area, pixels)
rasterImage.save(join_path(directory, "sample.SaveCmyk32Pixels.png"))
The following example crops a raster image. The cropping area is be specified via aspose.imaging.Rectangle.
from aspose.pycore import as_of
from aspose.imaging import Image, RasterImage, Rectangle
from os.path import join as join_path
directory = r"c:\temp"
with Image.load(join_path(directory, "sample.png")) as image:
rasterImage = as_of(image, RasterImage)
# Crop the image. The cropping area is the rectangular central area of the image.
area = Rectangle(rasterImage.width // 4, rasterImage.height // 4, rasterImage.width // 2, rasterImage.height // 2)
rasterImage.crop(area)
# Save the cropped image to PNG
rasterImage.save(join_path(directory, "sample.Crop.png"))
The following example crops a raster image. The cropping area is specified via Left, Top, Right, Bottom margins.
from aspose.pycore import as_of
from aspose.imaging import Image, RasterImage, Rectangle, Color
from os.path import join as join_path
directory = r"c:\temp"
with Image.load(join_path(directory, "sample.png")) as image:
rasterImage = as_of(image, RasterImage)
# Crop again. Set a margin of 10% of the image size.
horizontalMargin = rasterImage.width // 10
verticalMargin = rasterImage.height // 10
rasterImage.crop(horizontalMargin, horizontalMargin, verticalMargin, verticalMargin)
# Save the cropped image to PNG.
rasterImage.save(join_path(directory, "sample.Crop.png"))
The following example binarizes a raster image with the predefined threshold. Binarized images contain only 2 colors - black and white.
from aspose.pycore import as_of
from aspose.imaging import Image, RasterImage
from os.path import join as join_path
directory = r"c:\temp"
with Image.load(join_path(directory, "sample.png")) as image:
rasterImage = as_of(image, RasterImage)
# Binarize the image with a threshold value of 127.
# If a corresponding gray value of a pixel is greater than 127, a value of 255 will be assigned to it, 0 otherwise.
rasterImage.binarize_fixed(127)
rasterImage.save(join_path(directory, "sample.BinarizeFixed.png"))
The following example binarizes a raster image with Bradley’s adaptive thresholding algorithm with the specified window size. Binarized images contain only 2 colors - black and white.
from aspose.pycore import as_of
from aspose.imaging import Image, RasterImage
from os.path import join as join_path
directory = r"c:\temp"
with Image.load(join_path(directory, "sample.png")) as image:
rasterImage = as_of(image, RasterImage)
# Binarize the image with a brightness difference of 5. The brightness is a difference between a pixel and the average of an 10 x 10 window of pixels centered around this pixel.
rasterImage.binarize_bradley(5, 10)
rasterImage.save(join_path(directory, "sample.BinarizeBradley5_10x10.png"))
The following example performs gamma-correction of an image.
from aspose.pycore import as_of
from aspose.imaging import Image, RasterImage
from os.path import join as join_path
directory = r"c:\temp"
with Image.load(join_path(directory, "sample.png")) as image:
rasterImage = as_of(image, RasterImage)
# Set gamma coefficient for red, green and blue channels.
rasterImage.adjust_gamma(2.5f)
rasterImage.save(join_path(directory, "sample.AdjustGamma.png"))
The following example performs gamma-correction of an image applying different coefficients for color components.
from aspose.pycore import as_of
from aspose.imaging import Image, RasterImage
from os.path import join as join_path
directory = r"c:\temp"
with Image.load(join_path(directory, "sample.png")) as image:
rasterImage = as_of(image, RasterImage)
# Set gamma coefficient for red, green and blue channels.
rasterImage.adjust_gamma(1.5f, 2.5f, 3.5f)
rasterImage.save(join_path(directory, "sample.AdjustGamma.png"))
The following example performs brightness correction of an image.
from aspose.pycore import as_of
from aspose.imaging import Image, RasterImage
from os.path import join as join_path
directory = r"c:\temp"
with Image.load(join_path(directory, "sample.png")) as image:
rasterImage = as_of(image, RasterImage)
# Set the brightness value. The accepted values of brightness are in the range [-255, 255].
rasterImage.adjust_brightness(50)
rasterImage.save(join_path(directory, "sample.AdjustBrightness.png"))
The following example performs contrast correction of an image.
from aspose.pycore import as_of
from aspose.imaging import Image, RasterImage
from os.path import join as join_path
directory = r"c:\temp"
with Image.load(join_path(directory, "sample.png")) as image:
rasterImage = as_of(image, RasterImage)
# Set the contrast value. The accepted values of contrast are in the range [-100f, 100f].
rasterImage.adjust_contrast(50)
rasterImage.save(join_path(directory, "sample.AdjustContrast.png"))
The following example applies various types of filters to a raster image.
from aspose.pycore import as_of
from aspose.imaging import Image, RasterImage
from aspose.imaging.imagefilters.filteroptions import *
from os.path import join as join_path
directory = r"c:\temp"
with Image.load(join_path(directory, "sample.png")) as image:
rasterImage = as_of(image, RasterImage)
# Apply a median filter with a rectangle size of 5 to the entire image.
rasterImage.filter(rasterImage.bounds, MedianFilterOptions(5))
rasterImage.save(join_path(directory, "sample.MedianFilter.png"))
with Image.load(join_path(directory, "sample.png")) as image:
rasterImage = as_of(image, RasterImage)
# Apply a bilateral smoothing filter with a kernel size of 5 to the entire image.
rasterImage.filter(rasterImage.bounds, BilateralSmoothingFilterOptions(5))
rasterImage.save(join_path(directory, "sample.BilateralSmoothingFilter.png"))
with Image.load(join_path(directory, "sample.png")) as image:
rasterImage = as_of(image, RasterImage)
# Apply a Gaussian blur filter with a radius of 5 and a sigma value of 4.0 to the entire image.
rasterImage.filter(rasterImage.bounds, GaussianBlurFilterOptions(5, 4.0))
rasterImage.save(join_path(directory, "sample.GaussianBlurFilter.png"))
with Image.load(join_path(directory, "sample.png")) as image:
rasterImage = as_of(image, RasterImage)
# Apply a Gauss-Wiener filter with a radius of 5 and a smooth value of 4.0 to the entire image.
rasterImage.filter(rasterImage.bounds, GaussWienerFilterOptions(5, 4.0))
rasterImage.save(join_path(directory, "sample.GaussWienerFilter.png"))
with Image.load(join_path(directory, "sample.png")) as image:
rasterImage = as_of(image, RasterImage)
# Apply a motion wiener filter with a length of 5, a smooth value of 4.0 and an angle of 90.0 degrees to the entire image.
rasterImage.filter(rasterImage.bounds, MotionWienerFilterOptions(10, 1.0, 90.0))
rasterImage.save(join_path(directory, "sample.MotionWienerFilter.png"))
}
with Image.load(join_path(directory, "sample.png")) as image:
rasterImage = as_of(image, RasterImage)
# Apply a sharpen filter with a kernel size of 5 and a sigma value of 4.0 to the entire image.
rasterImage.filter(rasterImage.bounds, SharpenFilterOptions(5, 4.0))
rasterImage.save(join_path(directory, "sample.SharpenFilter.png"))
This example loads a raster image and resizes it using various resizing methods.
from aspose.pycore import as_of
from aspose.imaging import Image, RasterImage, ResizeType
from os.path import join as join_path
directory = r"c:\temp"
with Image.load(join_path(directory, "sample.gif")) as image:
rasterImage = as_of(image, RasterImage)
# Scale up by 2 times using Nearest Neighbour resampling.
rasterImage.resize(image.width * 2, image.height * 2, ResizeType.NEAREST_NEIGHBOUR_RESAMPLE)
image.save(join_path(directory, "upsample.nearestneighbour.gif"))
with Image.load(join_path(directory, "sample.gif")) as image:
rasterImage = as_of(image, RasterImage)
# Scale down by 2 times using Nearest Neighbour resampling.
rasterImage.resize(image.width // 2, image.height // 2, ResizeType.NEAREST_NEIGHBOUR_RESAMPLE);
image.Save(dir + "downsample.nearestneighbour.gif");
with Image.load(join_path(directory, "sample.gif")) as image:
rasterImage = as_of(image, RasterImage)
# Scale up by 2 times using Bilinear resampling.
rasterImage.resize(image.width * 2, image.height * 2, ResizeType.BILINEAR_RESAMPLE)
image.save(join_path(directory, "upsample.bilinear.gif"))
with Image.load(join_path(directory, "sample.gif")) as image:
rasterImage = as_of(image, RasterImage)
# Scale down by 2 times using Bilinear resampling.
rasterImage.resize(image.width // 2, image.height // 2, ResizeType.BILINEAR_RESAMPLE)
image.Save(dir + "downsample.bilinear.gif");
This example loads a raster image and resizes it using various resizing settings.
from aspose.pycore import as_of
from aspose.imaging import Image, RasterImage, ImageResizeSettings, ResizeType,\
ImageFilterType, ColorQuantizationMethod, ColorCompareMethod
from os.path import join as join_path
directory = r"c:\temp"
resizeSettings = ImageResizeSettings()
# The adaptive algorithm based on weighted and blended rational function and lanczos3 interpolation.
resizeSettings.mode = ResizeType.ADAPTIVE_RESAMPLE
# The small rectangular filter
resizeSettings.filter_type = ImageFilterType.SMALL_RECTANGULAR
# The number of colors in the palette.
resizeSettings.entries_count = 256
# The color quantization is not used
resizeSettings.color_quantization_method = ColorQuantizationMethod.NONE
# The euclidian method
resizeSettings.color_compare_method = ColorCompareMethod.EUCLIDIAN
with Image.load(join_path(directory, "sample.gif")) as image:
rasterImage = as_of(image, RasterImage)
# Scale down by 2 times using adaptive resampling.
rasterImage.resize(image.width // 2, image.height // 2, resizeSettings)
image.save(join_path(directory, "downsample.adaptive.gif"))
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