BmpImage 类
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, IMetadataContainer, IHasExifData, IHasMetadata, IHasXmpData, IRasterImageArgb32PixelLoader, IRasterImageRawDataLoader, RasterCachedImage
Constructors
| Name | 描述 |
|---|---|
| BmpImage(path) | 使用此构造函数轻松开始使用 BmpImage 类 初始化新实例。非常适合希望快速上手并 高效使用 BmpImage 对象的开发者。 |
| BmpImage(path, bits_per_pixel, compression, horizontal_resolution, vertical_resolution) | 使用此构造函数轻松创建 BmpImage 类的新实例, 并使用指定的参数,如路径、bitsPerPixel 和 compression。非常适合希望快速高效初始化 BmpImage 对象,并对图像特性进行精确控制的开发者。 |
| BmpImage(raster_image) | 通过使用 RasterImage 对象初始化,轻松创建 BmpImage 类的新实例 。非常适合希望无缝将现有光栅图像转换为 BmpImage 格式,确保兼容性并便于在项目中集成的开发者。 |
| BmpImage(raster_image, bits_per_pixel, compression, horizontal_resolution, vertical_resolution) | 通过创建新实例并使用 rasterImage 以及 bitsPerPixel 和 compression 等指定参数,轻松开始使用 BmpImage 类 。非常适合寻求简便方式处理 BmpImage 对象,确保项目灵活性和效率的开发者。 |
| BmpImage(stream) | 通过此构造函数使用流作为输入,轻松初始化新实例,开始使用 BmpImage 类 。非常适合希望方便地从各种数据源处理 BmpImage 对象,确保灵活性和易于集成的开发者。 |
| BmpImage(stream, bits_per_pixel, compression, horizontal_resolution, vertical_resolution) | 通过使用流创建新实例,并指定 bitsPerPixel 和 compression 等参数,轻松开始使用 BmpImage 类 。非常适合寻求简便方式处理 BmpImage 对象,确保项目灵活性和效率的开发者。 |
| BmpImage(width, height) | 通过指定宽度和高度参数创建新实例,轻松开始使用 BmpImage 类 。非常适合希望方便生成自定义尺寸 BmpImage 对象,确保项目灵活性和易于集成的开发者。 |
| BmpImage(width, height, bits_per_pixel, palette) | 通过使用宽度、长度、位深度和调色板等参数初始化新实例,轻松开始使用 BmpImage 类 。非常适合希望简便创建具有自定义尺寸和颜色配置的 BmpImage 对象,确保项目灵活性和效率的开发者。 |
| BmpImage(width, height, bits_per_pixel, palette, compression, horizontal_resolution, vertical_resolution) | 使用此构造函数轻松创建 BmpImage 类的新实例, 并指定宽度、长度、bitsPerPixel 和调色板等参数。非常适合希望方便生成具有自定义尺寸和颜色配置的 BmpImage 对象,确保项目灵活性和易于集成的开发者。 |
Properties
| Name | Type | Access | 描述 |
|---|---|---|---|
| auto_adjust_palette | bool | r/w | 获取或设置一个值,指示是否自动调整调色板。 |
| background_color | Color | r/w | 获取或设置背景颜色的值。 |
| bitmap_info_header | BitmapInfoHeader | r | 使用此简洁函数快速获取位图图像的关键细节。 非常适合需要检索图像头信息的开发者。 |
| bits_per_pixel | int | r | 使用此属性轻松获取图像的每像素位数。 非常适合需要快速了解图像质量和深度信息的开发者。 |
| bounds | Rectangle | r | 获取对象的边界。 |
| buffer_size_hint | int | r/w | 获取或设置缓冲区大小提示,该提示定义了所有内部缓冲区的最大允许大小。 |
| compression | BitmapCompression | r | 使用此属性轻松检索图像使用的压缩类型。 非常适合需要快速获取图像压缩信息的开发者。 |
| container | Image | r | 获取 Image 容器。 |
| data_stream_container | StreamContainer | r | 获取对象的数据流。 |
| disposed | bool | r | 获取一个值,指示此实例是否已释放。 |
| exif_data | ExifData | r/w | 获取或设置 Exif 实例。 |
| file_format | FileFormat | r | 使用此友好的属性轻松检索文件格式值。 适用于希望快速获取文件格式信息的开发者。 |
| has_alpha | bool | r | 获取指示此实例是否具有 alpha 的值。 |
| has_background_color | bool | r/w | 获取或设置指示图像是否具有背景颜色的值。 |
| has_transparent_color | bool | r/w | 获取或设置指示此 RasterImage 实例是否具有透明颜色的值。 |
| height | int | r | 使用此属性轻松检索图像的高度。适用于开发者 需要快速获取图像尺寸信息。 |
| horizontal_resolution | float | r/w | 此属性允许您轻松获取或设置 RasterImage 对象的水平分辨率, 以每英寸像素为单位。适用于 需要在其应用程序中精确控制图像分辨率的开发者。 |
| image_opacity | float | r | 获取此图像的不透明度。 |
| interrupt_monitor | InterruptMonitor | r/w | 获取或设置中断监视器。 |
| is_cached | bool | r | 获取指示图像数据当前是否已缓存的值。 |
| is_raw_data_available | bool | r | 获取指示是否支持原始数据加载的值。 |
| metadata | ImageMetadata | r | 获取图像元数据。 |
| palette | IColorPalette | r/w | 获取或设置颜色调色板。当像素直接表示时,不使用颜色调色板。 |
| premultiply_components | bool | r/w | 获取或设置一个值,指示图像组件是否必须进行预乘。 |
| raw_custom_color_converter | IColorConverter | r/w | 获取或设置自定义颜色转换器 |
| raw_data_format | PixelDataFormat | r | 使用此友好函数轻松获取原始数据的格式。 非常适合希望快速获取其数据格式关键信息的开发者。 |
| raw_data_settings | RawDataSettings | r | 获取当前原始数据设置。注意,使用这些设置时,数据将在不进行转换的情况下加载。 |
| raw_fallback_index | int | r/w | 获取或设置当调色板索引超出范围时使用的回退索引 |
| raw_indexed_color_converter | IIndexedColorConverter | r/w | 获取或设置索引颜色转换器 |
| raw_line_size | int | r | 使用此直接属性快速获取每行原始数据的字节大小。 适用于需要高效处理原始图像数据的开发者。 |
| size | Size | r | 获取对象大小。 |
| transparent_color | Color | r/w | 获取图像的透明颜色。 |
| update_xmp_data | bool | r/w | 获取或设置一个值,指示是否更新 XMP 元数据。 |
| use_palette | bool | r | 获取一个值,指示是否使用图像调色板。 |
| use_raw_data | bool | r/w | 获取或设置一个值,指示在可用原始数据加载时是否使用原始数据加载。 |
| vertical_resolution | float | r/w | 使用此属性轻松获取或设置此 RasterImage 对象的垂直分辨率, 以每英寸像素为单位。非常适合需要在其应用程序中精确控制图像分辨率的开发者。 |
| width | int | r | 使用此属性轻松获取图像的宽度。适用于开发者 寻求快速获取图像尺寸信息。 |
| xmp_data | XmpPacketWrapper | r/w | 获取或设置 Xmp 数据。 |
Methods
Constructor: BmpImage(path)
BmpImage(path)
使用此构造函数轻松开始使用 BmpImage 类
初始化新实例。非常适合希望快速上手并
高效使用 BmpImage 对象的开发者。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 路径 | string | 用于加载图像并初始化像素和调色板数据的路径。 |
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)
使用此构造函数轻松创建 BmpImage 类的新实例,
并使用指定的参数,如路径、bitsPerPixel 和 compression。非常适合希望快速高效初始化 BmpImage 对象,并对图像特性进行精确控制的开发者。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 路径 | string | 用于加载图像并初始化像素和调色板数据的路径。 |
| bits_per_pixel | int | 每像素位数。 |
| compression | BitmapCompression | 要使用的压缩方式。 |
| horizontal_resolution | float | 水平分辨率。注意,由于四舍五入,得到的分辨率可能与传入的略有差异。 |
| vertical_resolution | float | 垂直分辨率。注意,由于四舍五入,得到的分辨率可能与传入的略有差异。 |
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)
通过使用 RasterImage 对象初始化,轻松创建 BmpImage 类的新实例
。非常适合希望无缝将现有光栅图像转换为 BmpImage 格式,确保兼容性并便于在项目中集成的开发者。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| raster_image | RasterImage | 用于初始化像素和调色板数据的图像。 |
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)
通过创建新实例并使用 rasterImage 以及 bitsPerPixel 和 compression 等指定参数,轻松开始使用 BmpImage 类
。非常适合寻求简便方式处理 BmpImage 对象,确保项目灵活性和效率的开发者。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| raster_image | RasterImage | 用于初始化像素和调色板数据的图像。 |
| bits_per_pixel | int | 每像素位数。 |
| compression | BitmapCompression | 要使用的压缩方式。 |
| horizontal_resolution | float | 水平分辨率。注意,由于四舍五入,得到的分辨率可能与传入的略有差异。 |
| vertical_resolution | float | 垂直分辨率。注意,由于四舍五入,得到的分辨率可能与传入的略有差异。 |
See also:
Example # 1: The example shows how to load a BmpImage from another instance of RasterImage…
Constructor: BmpImage(stream)
BmpImage(stream)
通过此构造函数使用流作为输入,轻松初始化新实例,开始使用 BmpImage 类
。非常适合希望方便地从各种数据源处理 BmpImage 对象,确保灵活性和易于集成的开发者。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 流 | _io.BufferedRandom | 用于加载图像并初始化像素和调色板数据的流。 |
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)
通过使用流创建新实例,并指定 bitsPerPixel
和 compression 等参数,轻松开始使用 BmpImage 类
。非常适合寻求简便方式处理 BmpImage 对象,确保项目灵活性和效率的开发者。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 流 | _io.BufferedRandom | 用于加载图像并初始化像素和调色板数据的流。 |
| bits_per_pixel | int | 每像素位数。 |
| compression | BitmapCompression | 要使用的压缩方式。 |
| horizontal_resolution | float | 水平分辨率。注意,由于四舍五入,得到的分辨率可能与传入的略有差异。 |
| vertical_resolution | float | 垂直分辨率。注意,由于四舍五入,得到的分辨率可能与传入的略有差异。 |
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)
通过指定宽度和高度参数创建新实例,轻松开始使用 BmpImage 类
。非常适合希望方便生成自定义尺寸 BmpImage 对象,确保项目灵活性和易于集成的开发者。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| width | int | 图像宽度。 |
| height | int | 图像高度。 |
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)
通过使用宽度、长度、位深度和调色板等参数初始化新实例,轻松开始使用 BmpImage 类
。非常适合希望简便创建具有自定义尺寸和颜色配置的 BmpImage 对象,确保项目灵活性和效率的开发者。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| width | int | 图像宽度。 |
| height | int | 图像高度。 |
| bits_per_pixel | int | 每像素位数。 |
| palette | IColorPalette | 颜色调色板。 |
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)
使用此构造函数轻松创建 BmpImage 类的新实例,
并指定宽度、长度、bitsPerPixel 和调色板等参数。非常适合希望方便生成具有自定义尺寸和颜色配置的 BmpImage 对象,确保项目灵活性和易于集成的开发者。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| width | int | 图像宽度。 |
| height | int | 图像高度。 |
| bits_per_pixel | int | 每像素位数。 |
| palette | IColorPalette | 颜色调色板。 |
| compression | BitmapCompression | 要使用的压缩方式。 |
| horizontal_resolution | float | 水平分辨率。注意,由于四舍五入,得到的分辨率可能与传入的略有差异。 |
| vertical_resolution | float | 垂直分辨率。注意,由于四舍五入,得到的分辨率可能与传入的略有差异。 |
See also:
Example # 1: The example shows how to create a BmpImage using various options.
Property: bitmap_info_header
使用此简洁函数快速获取位图图像的关键细节。
非常适合需要检索图像头信息的开发者。
See also:
Example # 1: The following example gets the information from the BMP header and prints it …
Property: bits_per_pixel
使用此属性轻松获取图像的每像素位数。
非常适合需要快速了解图像质量和深度信息的开发者。
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
使用此属性轻松检索图像使用的压缩类型。
非常适合需要快速获取图像压缩信息的开发者。
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
使用此友好的属性轻松检索文件格式值。
适用于希望快速获取文件格式信息的开发者。
See also:
Example # 1: The following example shows how to extract information about raw data format …
Property: height
使用此属性轻松检索图像的高度。适用于开发者
需要快速获取图像尺寸信息。
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
此属性允许您轻松获取或设置 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…
Property: raw_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
使用此直接属性快速获取每行原始数据的字节大小。
适用于需要高效处理原始图像数据的开发者。
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
使用此属性轻松获取或设置此 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…
Property: width
使用此属性轻松获取图像的宽度。适用于开发者
寻求快速获取图像尺寸信息。
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)
调整图像的亮度。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 亮度 | int | 亮度值。 |
Method: adjust_contrast(contrast)
adjust_contrast(contrast)
图像对比
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 对比度 | float | 对比度值(范围为 [-100; 100]) |
Method: adjust_gamma(gamma)
adjust_gamma(gamma)
图像的伽马校正。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 伽马 | float | 红、绿、蓝通道的伽马系数 |
Method: adjust_gamma(gamma_red, gamma_green, gamma_blue)
adjust_gamma(gamma_red, gamma_green, gamma_blue)
图像的伽马校正。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| gamma_red | float | 红色通道的伽马系数 |
| gamma_green | float | 绿色通道的伽马系数 |
| gamma_blue | float | 蓝色通道系数的 Gamma |
Method: analyze_percentage_digital_signature(password)
analyze_percentage_digital_signature(password)
计算提取数据与原始密码之间的相似度百分比。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 密码 | string | 用于提取嵌入数据的密码。 |
Returns
| Type | Description |
|---|---|
| int | 百分比相似度值。 |
Method: binarize_bradley(brightness_difference)
binarize_bradley(brightness_difference)
使用 Bradley 的自适应阈值算法和积分图阈值进行图像二值化
Parameters:
| 参数 | Type | Description |
|---|---|---|
| brightness_difference | float | 像素与其周围以该像素为中心的 s x s 窗口像素平均值之间的亮度差。 |
Method: binarize_bradley(brightness_difference, window_size)
binarize_bradley(brightness_difference, window_size)
使用 Bradley 的自适应阈值算法和积分图阈值进行图像二值化
Parameters:
| 参数 | Type | Description |
|---|---|---|
| brightness_difference | float | 像素与其周围以该像素为中心的 s x s 窗口像素平均值之间的亮度差。 |
| window_size | int | 以该像素为中心的 s x s 像素窗口的大小 |
Method: binarize_fixed(threshold)
binarize_fixed(threshold)
使用预定义阈值对图像进行二值化
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 阈值 | System.Byte | 阈值。如果像素的对应灰度值大于阈值,则赋值为 255,否则为 0。 |
Method: blend(origin, overlay, overlay_alpha)
blend(origin, overlay, overlay_alpha)
将此图像实例与 overlay 图像混合。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| origin | Point | 背景图像混合的原点。 |
| overlay | RasterImage | 覆盖图像。 |
| overlay_alpha | System.Byte | 覆盖的 alpha。 |
Method: blend(origin, overlay, overlay_area, overlay_alpha)
blend(origin, overlay, overlay_area, overlay_alpha)
将此图像实例与 overlay 图像混合。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| origin | Point | 背景图像混合的原点。 |
| overlay | RasterImage | 覆盖图像。 |
| overlay_area | Rectangle | 覆盖区域。 |
| overlay_alpha | System.Byte | 覆盖的 alpha。 |
Method: can_load(file_path) [static]
can_load(file_path)
确定是否可以从指定的文件路径加载图像。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| file_path | string | 文件路径。 |
Returns
| Type | Description |
|---|---|
| bool |
Method: can_load(file_path, load_options) [static]
can_load(file_path, load_options)
确定是否可以从指定的文件路径加载图像,并可选地使用指定的打开选项。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| file_path | string | 文件路径。 |
| load_options | LoadOptions | 加载选项。 |
Returns
| Type | Description |
|---|---|
| bool |
Method: can_load(stream) [static]
can_load(stream)
确定是否可以从指定的流加载图像。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 流 | _io.BufferedRandom | 要加载的流。 |
Returns
| Type | Description |
|---|---|
| bool |
Method: can_load(stream, load_options) [static]
can_load(stream, load_options)
确定是否可以从指定的流加载图像,并可选地使用指定的 loadOptions。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 流 | _io.BufferedRandom | 要加载的流。 |
| load_options | LoadOptions | 加载选项。 |
Returns
| Type | Description |
|---|---|
| bool |
Method: can_load_stream(stream) [static]
can_load_stream(stream)
确定是否可以从指定的流加载图像。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 流 | _io.BufferedRandom | 要加载的流。 |
Returns
| Type | Description |
|---|---|
| bool |
Method: can_load_stream_with_options(stream, load_options) [static]
can_load_stream_with_options(stream, load_options)
确定是否可以从指定的流加载图像,并可选地使用指定的 loadOptions。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 流 | _io.BufferedRandom | 要加载的流。 |
| load_options | LoadOptions | 加载选项。 |
Returns
| Type | Description |
|---|---|
| bool |
Method: can_load_with_options(file_path, load_options) [static]
can_load_with_options(file_path, load_options)
确定是否可以从指定的文件路径加载图像,并可选地使用指定的打开选项。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| file_path | string | 文件路径。 |
| load_options | LoadOptions | 加载选项。 |
Returns
| Type | Description |
|---|---|
| bool |
Method: can_save(options)
can_save(options)
确定是否可以将图像保存为由传入的保存选项表示的指定文件格式。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| options | ImageOptionsBase | 要使用的保存选项。 |
Returns
| Type | Description |
|---|---|
| bool |
Method: create(files) [static]
create(files)
创建包含指定文件的多页图像。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 文件 | string[] | 文件。 |
Returns
| Type | Description |
|---|---|
| Image | 多页图像 |
Method: create(files, throw_exception_on_load_error) [static]
create(files, throw_exception_on_load_error)
创建包含指定文件的多页图像。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 文件 | string[] | 文件。 |
| throw_exception_on_load_error | bool | 如果设置为 |
Returns
| Type | Description |
|---|---|
| Image | 多页图像 |
Method: create(image_options, width, height) [static]
create(image_options, width, height)
使用指定的创建选项创建新图像。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| image_options | ImageOptionsBase | 图像选项。 |
| width | int | 宽度。 |
| height | int | 高度。 |
Returns
| Type | Description |
|---|---|
| Image | 新创建的图像。 |
Method: create(image_options, width, height, pixels) [static]
create(image_options, width, height, pixels)
创建一个来自提供的像素数组的 RasterImage 实例。
验证指定的宽度和高度是否与像素数据的维度匹配。
仅当库处于授权模式时才能使用此方法。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| image_options | ImageOptionsBase | 用于创建 RasterImage 的选项。 |
| width | int | RasterImage 的宽度。 |
| height | int | RasterImage 的高度。 |
| 像素 | int[] | 用于填充图像的像素值数组。 |
Returns
| Type | Description |
|---|---|
| Image | 使用提供的像素数据填充的 RasterImage。 |
Method: create(images) [static]
create(images)
使用指定的图像作为页面创建新图像。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| images | Image[] | 图像。 |
Returns
| Type | Description |
|---|---|
| Image | Image 作为 IMultipageImage |
Method: create(images, dispose_images) [static]
create(images, dispose_images)
创建一个新图像,将指定的图像作为页面。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| images | Image[] | 图像。 |
| dispose_images | bool | 如果设置为 |
Returns
| Type | Description |
|---|---|
| Image | Image 作为 IMultipageImage |
Method: create(multipage_create_options) [static]
create(multipage_create_options)
创建指定的多页创建选项。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| multipage_create_options | MultipageCreateOptions | 多页创建选项。 |
Returns
| Type | Description |
|---|---|
| Image | 多页图像 |
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)
使用此构造函数轻松开始使用 BmpImage 类,简化
新实例的初始化过程。适用于希望快速高效地将 BmpImage 对象整合到项目中的开发者。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 路径 | string | 用于加载图像并初始化像素和调色板数据的路径。 |
| bits_per_pixel | int | 每像素位数。 |
| compression | BitmapCompression | 要使用的压缩方式。 |
| horizontal_resolution | float | 水平分辨率。注意,由于四舍五入,得到的分辨率可能与传入的略有差异。 |
| vertical_resolution | float | 垂直分辨率。注意,由于四舍五入,得到的分辨率可能与传入的略有差异。 |
Returns
| Type | Description |
|---|---|
| BmpImage |
Method: create_from_files(files) [static]
create_from_files(files)
创建包含指定文件的多页图像,将其作为延迟加载页面。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 文件 | string[] | 文件。 |
Returns
| Type | Description |
|---|---|
| Image | 多页图像 |
Method: create_from_files(files, throw_exception_on_load_error) [static]
create_from_files(files, throw_exception_on_load_error)
创建包含指定文件的多页图像,将其作为延迟加载页面。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 文件 | string[] | 文件。 |
| throw_exception_on_load_error | bool | 如果设置为 |
Returns
| Type | Description |
|---|---|
| Image | 多页图像 |
Method: create_from_image(raster_image) [static]
create_from_image(raster_image)
初始化 BmpImage 类的新实例。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| raster_image | RasterImage | 用于初始化像素和调色板数据的图像。 |
Returns
| Type | Description |
|---|---|
| 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)
初始化 BmpImage 类的新实例。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| raster_image | RasterImage | 用于初始化像素和调色板数据的图像。 |
| bits_per_pixel | int | 每像素位数。 |
| compression | BitmapCompression | 要使用的压缩方式。 |
| horizontal_resolution | float | 水平分辨率。注意,由于四舍五入,得到的分辨率可能与传入的略有差异。 |
| vertical_resolution | float | 垂直分辨率。注意,由于四舍五入,得到的分辨率可能与传入的略有差异。 |
Returns
| Type | Description |
|---|---|
| BmpImage |
Method: create_from_images(images) [static]
create_from_images(images)
使用指定的图像作为页面创建新图像。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| images | Image[] | 图像。 |
Returns
| Type | Description |
|---|---|
| Image | Image 作为 IMultipageImage |
Method: create_from_images(images, dispose_images) [static]
create_from_images(images, dispose_images)
创建一个新图像,将指定的图像作为页面。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| images | Image[] | 图像。 |
| dispose_images | bool | 如果设置为 |
Returns
| Type | Description |
|---|---|
| Image | Image 作为 IMultipageImage |
Method: create_from_stream(stream) [static]
create_from_stream(stream)
初始化 BmpImage 类的新实例。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 流 | _io.BufferedRandom | 用于加载图像并初始化像素和调色板数据的流。 |
Returns
| Type | Description |
|---|---|
| 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)
初始化 BmpImage 类的新实例。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 流 | _io.BufferedRandom | 用于加载图像并初始化像素和调色板数据的流。 |
| bits_per_pixel | int | 每像素位数。 |
| compression | BitmapCompression | 要使用的压缩方式。 |
| horizontal_resolution | float | 水平分辨率。注意,由于四舍五入,得到的分辨率可能与传入的略有差异。 |
| vertical_resolution | float | 垂直分辨率。注意,由于四舍五入,得到的分辨率可能与传入的略有差异。 |
Returns
| Type | Description |
|---|---|
| BmpImage |
Method: crop(left_shift, right_shift, top_shift, bottom_shift)
crop(left_shift, right_shift, top_shift, bottom_shift)
使用位移裁剪图像。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| left_shift | int | 左移。 |
| right_shift | int | 右移。 |
| top_shift | int | 上移。 |
| bottom_shift | int | 下移。 |
Method: crop(rectangle)
crop(rectangle)
裁剪图像。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| rectangle | Rectangle | 矩形。 |
Method: dither(dithering_method, bits_count)
dither(dithering_method, bits_count)
对当前图像执行抖动处理。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| dithering_method | DitheringMethod | 抖动方法。 |
| bits_count | int | 用于抖动的最终位计数。 |
Method: dither(dithering_method, bits_count, custom_palette)
dither(dithering_method, bits_count, custom_palette)
对当前图像执行抖动处理。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| dithering_method | DitheringMethod | 抖动方法。 |
| bits_count | int | 用于抖动的最终位计数。 |
| custom_palette | IColorPalette | 用于抖动的自定义调色板。 |
Method: embed_digital_signature(password)
embed_digital_signature(password)
使用隐写术将基于提供的密码的数字签名嵌入图像中。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 密码 | string | 用于生成数字签名数据的密码 |
Method: filter(rectangle, options)
filter(rectangle, options)
过滤指定的矩形区域。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| rectangle | Rectangle | 矩形。 |
| options | FilterOptionsBase | 选项。 |
Method: get_argb_32_pixel(x, y)
get_argb_32_pixel(x, y)
获取图像的 32 位 ARGB 像素。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| x | int | 像素的 x 位置。 |
| y | int | 像素的 y 位置。 |
Returns
| Type | Description |
|---|---|
| int | 指定位置的 32 位 ARGB 像素。 |
Method: get_default_argb_32_pixels(rectangle)
get_default_argb_32_pixels(rectangle)
获取默认的 32 位 ARGB 像素数组。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| rectangle | Rectangle | 用于获取像素的矩形。 |
Returns
| Type | Description |
|---|---|
| int[] | 默认像素数组。 |
Method: get_default_options(args)
get_default_options(args)
使用此直接方法轻松检索默认选项。
适用于希望快速获取默认图像设置或配置的开发者。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| args | System.Object | 参数。 |
Returns
| Type | Description |
|---|---|
| ImageOptionsBase | 默认选项 |
Method: get_default_pixels(rectangle, partial_pixel_loader)
get_default_pixels(rectangle, partial_pixel_loader)
使用部分像素加载器获取默认像素数组。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| rectangle | Rectangle | 用于获取像素的矩形。 |
| partial_pixel_loader | IPartialArgb32PixelLoader | 部分像素加载器。 |
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)
使用部分像素加载器获取默认原始数据数组。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| rectangle | Rectangle | 用于获取像素的矩形。 |
| partial_raw_data_loader | IPartialRawDataLoader | 部分原始数据加载器。 |
| raw_data_settings | RawDataSettings | 原始数据设置。 |
Method: get_default_raw_data(rectangle, raw_data_settings)
get_default_raw_data(rectangle, raw_data_settings)
获取默认原始数据数组。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| rectangle | Rectangle | 用于获取原始数据的矩形。 |
| raw_data_settings | RawDataSettings | 原始数据设置。 |
Returns
| Type | Description |
|---|---|
| System.Byte | 默认原始数据数组。 |
Method: get_file_format(file_path) [static]
get_file_format(file_path)
获取文件格式。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| file_path | string | 文件路径。 |
Returns
| Type | Description |
|---|---|
| FileFormat | 确定的文件格式。 |
Method: get_file_format(stream) [static]
get_file_format(stream)
获取文件格式。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 流 | _io.BufferedRandom | 该流。 |
Returns
| Type | Description |
|---|---|
| FileFormat | 确定的文件格式。 |
Method: get_file_format_of_stream(stream) [static]
get_file_format_of_stream(stream)
获取文件格式。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 流 | _io.BufferedRandom | 该流。 |
Returns
| Type | Description |
|---|---|
| FileFormat | 确定的文件格式。 |
Method: get_fitting_rectangle(rectangle, pixels, width, height) [static]
get_fitting_rectangle(rectangle, pixels, width, height)
获取适合当前图像的矩形。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| rectangle | Rectangle | 用于获取合适矩形的矩形。 |
| 像素 | int[] | 32 位 ARGB 像素。 |
| width | int | 对象宽度。 |
| height | int | 对象高度。 |
Returns
| Type | Description |
|---|---|
| Rectangle | 适配矩形,若未找到适配矩形则抛出异常。 |
Method: get_fitting_rectangle(rectangle, width, height) [static]
get_fitting_rectangle(rectangle, width, height)
获取适合当前图像的矩形。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| rectangle | Rectangle | 用于获取合适矩形的矩形。 |
| width | int | 对象宽度。 |
| height | int | 对象高度。 |
Returns
| Type | Description |
|---|---|
| Rectangle | 适配矩形,若未找到适配矩形则抛出异常。 |
Method: get_modify_date(use_default)
get_modify_date(use_default)
获取资源图像最后修改的日期和时间。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| use_default | bool | 如果设置为 |
Returns
| Type | Description |
|---|---|
| System.DateTime | 资源图像上次修改的日期和时间。 |
Method: get_original_options()
get_original_options()
根据原始文件设置获取选项。
这有助于保持原始图像的位深度和其他参数不变。
例如,如果我们加载一个每像素 1 位的黑白 PNG 图像,然后使用
DataStreamSupporter.save(file_path) 方法保存,它将生成每像素 8 位的输出 PNG 图像。
为避免这种情况并以每像素 1 位保存 PNG 图像,请使用此方法获取相应的保存选项,并将其
作为第二个参数传递给 Image.save(file_path, options) 方法。
Returns
| Type | Description |
|---|---|
| ImageOptionsBase | 基于原始文件设置的选项。 |
Method: get_pixel(x, y)
get_pixel(x, y)
获取图像像素。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| x | int | 像素的 x 位置。 |
| y | int | 像素的 y 位置。 |
Returns
| Type | Description |
|---|---|
| Color | 指定位置的像素颜色。 |
Method: get_proportional_height(width, height, new_width) [static]
get_proportional_height(width, height, new_width)
获取比例高度。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| width | int | 宽度。 |
| height | int | 高度。 |
| new_width | int | 新的宽度。 |
Returns
| Type | Description |
|---|---|
| int | 比例高度。 |
Method: get_proportional_width(width, height, new_height) [static]
get_proportional_width(width, height, new_height)
获取比例宽度。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| width | int | 宽度。 |
| height | int | 高度。 |
| new_height | int | 新的高度。 |
Returns
| Type | Description |
|---|---|
| int | 比例宽度。 |
Method: get_serialized_stream(image_options, clipping_rectangle, page_number)
get_serialized_stream(image_options, clipping_rectangle, page_number)
转换为 aps。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| image_options | ImageOptionsBase | 图像选项。 |
| clipping_rectangle | Rectangle | 裁剪矩形。 |
| page_number | int[] | 页码。 |
Returns
| Type | Description |
|---|---|
| _io.BufferedRandom | 序列化流 |
Method: get_skew_angle()
get_skew_angle()
获取倾斜角度。
此方法适用于扫描的文本文件,用于在扫描时确定倾斜角度。
Returns
| Type | Description |
|---|---|
| float | 倾斜角度(单位:度)。 |
Method: is_digital_signed(password, percentage_threshold)
is_digital_signed(password, percentage_threshold)
使用提供的密码和阈值执行快速检查,以确定图像是否已数字签名。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 密码 | string | 用于检查签名的密码。 |
| percentage_threshold | int | 阈值(百分比)[0-100] 用于确定图像是否被视为已签名。 如果未指定,将使用默认阈值( |
Returns
| Type | Description |
|---|---|
| bool | 如果图像已签名则为 true,否则为 false。 |
Method: load(file_path) [static]
load(file_path)
从指定的文件路径或 URL 加载新图像。
如果 filePath 是文件路径,方法仅打开该文件。
如果 filePath 是 URL,方法会下载文件,将其存为临时文件,然后打开它。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| file_path | string | 加载图像的文件路径或 URL。 |
Returns
| Type | Description |
|---|---|
| Image | 已加载的图像。 |
Method: load(file_path, load_options) [static]
load(file_path, load_options)
从指定的文件路径或 URL 加载新图像。
如果 filePath 是文件路径,方法仅打开该文件。
如果 filePath 是 URL,方法会下载文件,将其存为临时文件,然后打开它。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| file_path | string | 加载图像的文件路径或 URL。 |
| load_options | LoadOptions | 加载选项。 |
Returns
| Type | Description |
|---|---|
| Image | 已加载的图像。 |
Method: load(stream) [static]
load(stream)
从指定的流加载新图像。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 流 | _io.BufferedRandom | 加载图像的流。 |
Returns
| Type | Description |
|---|---|
| Image | 已加载的图像。 |
Method: load(stream, load_options) [static]
load(stream, load_options)
从指定的流加载新图像。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 流 | _io.BufferedRandom | 加载图像的流。 |
| load_options | LoadOptions | 加载选项。 |
Returns
| Type | Description |
|---|---|
| Image | 已加载的图像。 |
Method: load_argb_32_pixels(rectangle)
load_argb_32_pixels(rectangle)
加载 32 位 ARGB 像素。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| rectangle | Rectangle | 加载像素的矩形。 |
Returns
| Type | Description |
|---|---|
| int[] | 已加载的 32 位 ARGB 像素数组。 |
Method: load_argb_64_pixels(rectangle)
load_argb_64_pixels(rectangle)
加载 64 位 ARGB 像素。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| rectangle | Rectangle | 加载像素的矩形。 |
Returns
| Type | Description |
|---|---|
| int[] | 已加载的 64 位 ARGB 像素数组。 |
Method: load_cmyk_32_pixels(rectangle)
load_cmyk_32_pixels(rectangle)
加载 CMYK 格式的像素。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| rectangle | Rectangle | 加载像素的矩形。 |
Returns
| Type | Description |
|---|---|
| int[] | 已加载的 CMYK 像素以 32 位整数值呈现。 |
Method: load_cmyk_pixels(rectangle)
load_cmyk_pixels(rectangle)
加载 CMYK 格式的像素。
此方法已弃用。请使用更有效的 RasterImage.load_cmyk_32_pixels(rectangle) 方法。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| rectangle | Rectangle | 加载像素的矩形。 |
Returns
| Type | Description |
|---|---|
| CmykColor[] | 已加载的 CMYK 像素数组。 |
Method: load_partial_argb_32_pixels(rectangle, partial_pixel_loader)
load_partial_argb_32_pixels(rectangle, partial_pixel_loader)
部分加载 32 位 ARGB 像素(按块)。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| rectangle | Rectangle | 加载像素的矩形。 |
| partial_pixel_loader | IPartialArgb32PixelLoader | 部分像素加载器。 |
Method: load_partial_argb_64_pixels(rectangle, partial_pixel_loader)
load_partial_argb_64_pixels(rectangle, partial_pixel_loader)
按包部分加载 64 位 ARGB 像素。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| rectangle | Rectangle | 所需的矩形。 |
| partial_pixel_loader | IPartialArgb64PixelLoader | 64 位 ARGB 像素加载器。 |
Method: load_partial_pixels(desired_rectangle, pixel_loader)
load_partial_pixels(desired_rectangle, pixel_loader)
按包部分加载像素。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| desired_rectangle | Rectangle | 所需的矩形。 |
| pixel_loader | IPartialPixelLoader | 像素加载器。 |
Method: load_pixels(rectangle)
load_pixels(rectangle)
加载像素。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| rectangle | Rectangle | 加载像素的矩形。 |
Returns
| Type | Description |
|---|---|
| Color[] | 已加载的像素数组。 |
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)
加载原始数据。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| rectangle | Rectangle | 用于加载原始数据的矩形。 |
| dest_image_bounds | Rectangle | 目标图像边界。 |
| raw_data_settings | RawDataSettings | 用于已加载数据的原始数据设置。注意,如果数据不是指定的格式,则会执行数据转换。 |
| raw_data_loader | IPartialRawDataLoader | 原始数据加载器。 |
Method: load_raw_data(rectangle, raw_data_settings, raw_data_loader)
load_raw_data(rectangle, raw_data_settings, raw_data_loader)
加载原始数据。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| rectangle | Rectangle | 用于加载原始数据的矩形。 |
| raw_data_settings | RawDataSettings | 用于已加载数据的原始数据设置。注意,如果数据不是指定的格式,则会执行数据转换。 |
| raw_data_loader | IPartialRawDataLoader | 原始数据加载器。 |
Method: load_stream(stream) [static]
load_stream(stream)
从指定的流加载新图像。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 流 | _io.BufferedRandom | 加载图像的流。 |
Returns
| Type | Description |
|---|---|
| Image | 已加载的图像。 |
Method: load_stream_with_options(stream, load_options) [static]
load_stream_with_options(stream, load_options)
从指定的流加载新图像。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 流 | _io.BufferedRandom | 加载图像的流。 |
| load_options | LoadOptions | 加载选项。 |
Returns
| Type | Description |
|---|---|
| Image | 已加载的图像。 |
Method: load_with_options(file_path, load_options) [static]
load_with_options(file_path, load_options)
从指定的文件路径或 URL 加载新图像。
如果 filePath 是文件路径,方法仅打开该文件。
如果 filePath 是 URL,方法会下载文件,将其存为临时文件,然后打开它。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| file_path | string | 加载图像的文件路径或 URL。 |
| load_options | LoadOptions | 加载选项。 |
Returns
| Type | Description |
|---|---|
| Image | 已加载的图像。 |
Method: normalize_angle(resize_proportionally, background_color)
normalize_angle(resize_proportionally, background_color)
归一化角度。
此方法适用于扫描的文本文档,以消除倾斜扫描。
此方法使用 RasterImage.get_skew_angle() 和 RasterImage.rotate(angle, resize_proportionally, background_color) 方法。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| resize_proportionally | bool | 如果设置为 |
| background_color | Color | 背景颜色。 |
Method: read_argb_32_scan_line(scan_line_index)
read_argb_32_scan_line(scan_line_index)
按指定的扫描线索引读取整条扫描线。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| scan_line_index | int | 扫描线的零基索引。 |
Returns
| Type | Description |
|---|---|
| int[] | 扫描线 32 位 ARGB 颜色值数组。 |
Method: read_scan_line(scan_line_index)
read_scan_line(scan_line_index)
按指定的扫描线索引读取整条扫描线。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| scan_line_index | int | 扫描线的零基索引。 |
Returns
| Type | Description |
|---|---|
| Color[] | 扫描线像素颜色值数组。 |
Method: replace_argb(old_color_argb, old_color_diff, new_color_argb)
replace_argb(old_color_argb, old_color_diff, new_color_argb)
在允许的差异范围内将一种颜色替换为另一种颜色,并保留原始 alpha 值以保持平滑边缘。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| old_color_argb | int | 要替换的旧颜色 ARGB 值。 |
| old_color_diff | System.Byte | 允许的旧颜色差异,以便能够扩大替换颜色的色调。 |
| new_color_argb | int | 用于替换旧颜色的新颜色 ARGB 值。 |
Method: replace_color(old_color, old_color_diff, new_color)
replace_color(old_color, old_color_diff, new_color)
在允许的差异范围内将一种颜色替换为另一种颜色,并保留原始 alpha 值以保持平滑边缘。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| old_color | Color | 要被替换的旧颜色。 |
| old_color_diff | System.Byte | 允许的旧颜色差异,以便能够扩大替换颜色的色调。 |
| new_color | Color | 用于替换旧颜色的新颜色。 |
Method: replace_color(old_color_argb, old_color_diff, new_color_argb)
replace_color(old_color_argb, old_color_diff, new_color_argb)
在允许的差异范围内将一种颜色替换为另一种颜色,并保留原始 alpha 值以保持平滑边缘。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| old_color_argb | int | 要替换的旧颜色 ARGB 值。 |
| old_color_diff | System.Byte | 允许的旧颜色差异,以便能够扩大替换颜色的色调。 |
| new_color_argb | int | 用于替换旧颜色的新颜色 ARGB 值。 |
Method: replace_non_transparent_colors(new_color)
replace_non_transparent_colors(new_color)
将所有非透明颜色替换为新颜色,并保留原始的 alpha 值以保持平滑的边缘。
注意:如果在没有透明度的图像上使用,它将把所有颜色替换为单一颜色。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| new_color | Color | 用于替换非透明颜色的新颜色。 |
Method: replace_non_transparent_colors(new_color_argb)
replace_non_transparent_colors(new_color_argb)
将所有非透明颜色替换为新颜色,并保留原始的 alpha 值以保持平滑的边缘。
注意:如果在没有透明度的图像上使用,它将把所有颜色替换为单一颜色。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| new_color_argb | int | 用于替换非透明颜色的新颜色 ARGB 值。 |
Method: resize(new_width, new_height)
resize(new_width, new_height)
调整图像大小。使用默认的 ResizeType.NEAREST_NEIGHBOUR_RESAMPLE。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| new_width | int | 新的宽度。 |
| new_height | int | 新的高度。 |
Method: resize(new_width, new_height, resize_type)
resize(new_width, new_height, resize_type)
调整图像大小。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| new_width | int | 新的宽度。 |
| new_height | int | 新的高度。 |
| resize_type | ResizeType | 调整大小类型。 |
Method: resize(new_width, new_height, settings)
resize(new_width, new_height, settings)
调整图像大小。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| new_width | int | 新的宽度。 |
| new_height | int | 新的高度。 |
| settings | ImageResizeSettings | 调整大小设置。 |
Method: resize_by_settings(new_width, new_height, settings)
resize_by_settings(new_width, new_height, settings)
调整图像大小。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| new_width | int | 新的宽度。 |
| new_height | int | 新的高度。 |
| settings | ImageResizeSettings | 调整大小设置。 |
Method: resize_by_type(new_width, new_height, resize_type)
resize_by_type(new_width, new_height, resize_type)
调整图像大小。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| new_width | int | 新的宽度。 |
| new_height | int | 新的高度。 |
| resize_type | ResizeType | 调整大小类型。 |
Method: resize_height_proportionally(new_height)
resize_height_proportionally(new_height)
按比例调整高度。默认使用 ResizeType.NEAREST_NEIGHBOUR_RESAMPLE。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| new_height | int | 新的高度。 |
Method: resize_height_proportionally(new_height, resize_type)
resize_height_proportionally(new_height, resize_type)
按比例调整高度。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| new_height | int | 新的高度。 |
| resize_type | ResizeType | 调整大小的类型。 |
Method: resize_height_proportionally(new_height, settings)
resize_height_proportionally(new_height, settings)
按比例调整高度。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| new_height | int | 新的高度。 |
| settings | ImageResizeSettings | 图像调整大小设置。 |
Method: resize_height_proportionally_settings(new_height, settings)
resize_height_proportionally_settings(new_height, settings)
按比例调整高度。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| new_height | int | 新的高度。 |
| settings | ImageResizeSettings | 图像调整大小设置。 |
Method: resize_width_proportionally(new_width)
resize_width_proportionally(new_width)
按比例调整宽度。默认使用 ResizeType.NEAREST_NEIGHBOUR_RESAMPLE。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| new_width | int | 新的宽度。 |
Method: resize_width_proportionally(new_width, resize_type)
resize_width_proportionally(new_width, resize_type)
按比例调整宽度。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| new_width | int | 新的宽度。 |
| resize_type | ResizeType | 调整大小的类型。 |
Method: resize_width_proportionally(new_width, settings)
resize_width_proportionally(new_width, settings)
按比例调整宽度。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| new_width | int | 新的宽度。 |
| settings | ImageResizeSettings | 图像调整大小设置。 |
Method: resize_width_proportionally_settings(new_width, settings)
resize_width_proportionally_settings(new_width, settings)
按比例调整宽度。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| new_width | int | 新的宽度。 |
| settings | ImageResizeSettings | 图像调整大小设置。 |
Method: rotate(angle)
rotate(angle)
围绕中心旋转图像。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 角度 | float | 旋转角度(以度为单位)。正值将顺时针旋转。 |
Method: rotate(angle, resize_proportionally, background_color)
rotate(angle, resize_proportionally, background_color)
围绕中心旋转图像。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 角度 | float | 旋转角度(以度为单位)。正值将顺时针旋转。 |
| resize_proportionally | bool | 如果设置为 |
| background_color | Color | 背景颜色。 |
Method: rotate_flip(rotate_flip_type)
rotate_flip(rotate_flip_type)
旋转、翻转或同时旋转和翻转图像。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| rotate_flip_type | RotateFlipType | 旋转翻转类型。 |
Method: save(file_path)
save(file_path)
将图像保存到指定的文件位置。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| file_path | string | 保存图像的文件路径。 |
Method: save(file_path, options)
save(file_path, options)
根据保存选项,将对象的数据保存到指定文件位置的指定文件格式中。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| file_path | string | 文件路径。 |
| options | ImageOptionsBase | 选项。 |
Method: save(file_path, options, bounds_rectangle)
save(file_path, options, bounds_rectangle)
根据保存选项,将对象的数据保存到指定文件位置的指定文件格式中。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| file_path | string | 文件路径。 |
| options | ImageOptionsBase | 选项。 |
| bounds_rectangle | Rectangle | 目标图像边界矩形。将空矩形设置为使用源边界。 |
Method: save(file_path, over_write)
save(file_path, over_write)
将对象的数据保存到指定的文件位置。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| file_path | string | 保存对象数据的文件路径。 |
| over_write | bool | 如果设置为 |
Method: save(stream)
save(stream)
将对象的数据保存到指定的流中。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 流 | _io.BufferedRandom | 用于保存对象数据的流。 |
Method: save(stream, options_base)
save(stream, options_base)
根据保存选项,将图像的数据保存到指定流中的指定文件格式。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 流 | _io.BufferedRandom | 保存图像数据的流。 |
| options_base | ImageOptionsBase | 保存选项。 |
Method: save(stream, options_base, bounds_rectangle)
save(stream, options_base, bounds_rectangle)
根据保存选项,将图像的数据保存到指定流中的指定文件格式。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 流 | _io.BufferedRandom | 保存图像数据的流。 |
| options_base | ImageOptionsBase | 保存选项。 |
| bounds_rectangle | Rectangle | 目标图像边界矩形。将空矩形设置为使用源边界。 |
Method: save_argb_32_pixels(rectangle, pixels)
save_argb_32_pixels(rectangle, pixels)
保存 32 位 ARGB 像素。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| rectangle | Rectangle | 保存像素的矩形。 |
| 像素 | int[] | 32 位 ARGB 像素数组。 |
Method: save_cmyk_32_pixels(rectangle, pixels)
save_cmyk_32_pixels(rectangle, pixels)
保存像素。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| rectangle | Rectangle | 保存像素的矩形。 |
| 像素 | int[] | 以 32 位整数值表示的 CMYK 像素。 |
Method: save_cmyk_pixels(rectangle, pixels)
save_cmyk_pixels(rectangle, pixels)
保存像素。
此方法已弃用。请使用更有效的 RasterImage.save_cmyk_32_pixels(rectangle, pixels) 方法。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| rectangle | Rectangle | 保存像素的矩形。 |
| pixels | CmykColor[] | CMYK 像素数组。 |
Method: save_pixels(rectangle, pixels)
save_pixels(rectangle, pixels)
保存像素(特定格式方法)。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| rectangle | Rectangle | 保存像素的矩形。 |
| pixels | Color[] | 32 位 ARGB 像素数组。 |
Method: save_raw_data(data, data_offset, rectangle, raw_data_settings)
save_raw_data(data, data_offset, rectangle, raw_data_settings)
保存原始数据。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 数据 | System.Byte | 原始数据。 |
| data_offset | int | 起始原始数据偏移。 |
| rectangle | Rectangle | 原始数据矩形。 |
| raw_data_settings | RawDataSettings | 原始数据所在的设置。 |
Method: save_to_stream(stream)
save_to_stream(stream)
将对象的数据保存到指定的流中。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 流 | _io.BufferedRandom | 用于保存对象数据的流。 |
Method: save_to_stream_with_options(stream, options_base)
save_to_stream_with_options(stream, options_base)
根据保存选项,将图像的数据保存到指定流中的指定文件格式。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 流 | _io.BufferedRandom | 保存图像数据的流。 |
| options_base | ImageOptionsBase | 保存选项。 |
Method: save_to_stream_with_options_rect(stream, options_base, bounds_rectangle)
save_to_stream_with_options_rect(stream, options_base, bounds_rectangle)
根据保存选项,将图像的数据保存到指定流中的指定文件格式。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| 流 | _io.BufferedRandom | 保存图像数据的流。 |
| options_base | ImageOptionsBase | 保存选项。 |
| bounds_rectangle | Rectangle | 目标图像边界矩形。将空矩形设置为使用源边界。 |
Method: save_with_options(file_path, options)
save_with_options(file_path, options)
根据保存选项,将对象的数据保存到指定文件位置的指定文件格式中。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| file_path | string | 文件路径。 |
| options | ImageOptionsBase | 选项。 |
Method: save_with_options_rect(file_path, options, bounds_rectangle)
save_with_options_rect(file_path, options, bounds_rectangle)
根据保存选项,将对象的数据保存到指定文件位置的指定文件格式中。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| file_path | string | 文件路径。 |
| options | ImageOptionsBase | 选项。 |
| bounds_rectangle | Rectangle | 目标图像边界矩形。将空矩形设置为使用源边界。 |
Method: set_argb_32_pixel(x, y, argb_32_color)
set_argb_32_pixel(x, y, argb_32_color)
为指定位置设置图像的 32 位 ARGB 像素。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| x | int | 像素的 x 位置。 |
| y | int | 像素的 y 位置。 |
| argb_32_color | int | 指定位置的 32 位 ARGB 像素。 |
Method: set_palette(palette, update_colors)
set_palette(palette, update_colors)
设置图像调色板。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| palette | IColorPalette | 要设置的调色板。 |
| update_colors | bool | 如果设置为 |
Method: set_pixel(x, y, color)
set_pixel(x, y, color)
为指定位置设置图像像素。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| x | int | 像素的 x 位置。 |
| y | int | 像素的 y 位置。 |
| color | Color | 指定位置的像素颜色。 |
Method: set_resolution(dpi_x, dpi_y)
set_resolution(dpi_x, dpi_y)
使用此
友好方法轻松调整您的 RasterImage 的分辨率。非常适合希望在其应用程序中精确控制
图像分辨率的开发者。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| dpi_x | float | 以每英寸点数表示的 RasterImage 的水平分辨率。 |
| dpi_y | float | 以每英寸点数表示的 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: try_set_metadata(metadata)
try_set_metadata(metadata)
尝试设置一个 metadata 实例,前提是此 Image 实例支持并实现 IImageMetadataFormat 实例。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| metadata | IImageMetadataFormat | 元数据。 |
Returns
| Type | Description |
|---|---|
| bool | 如果 metadata 不为 null 且 IMetadataContainer 实例 支持和/或实现 IImageMetadataFormat 实例,则为 true;否则为 false。 |
Method: write_argb_32_scan_line(scan_line_index, argb_32_pixels)
write_argb_32_scan_line(scan_line_index, argb_32_pixels)
将整条扫描线写入指定的扫描线索引。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| scan_line_index | int | 扫描线的零基索引。 |
| argb_32_pixels | int[] | 要写入的 32 位 ARGB 颜色数组。 |
Method: write_scan_line(scan_line_index, pixels)
write_scan_line(scan_line_index, pixels)
将整条扫描线写入指定的扫描线索引。
Parameters:
| 参数 | Type | Description |
|---|---|---|
| scan_line_index | int | 扫描线的零基索引。 |
| pixels | Color[] | 要写入的像素颜色数组。 |
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\\"
# 创建一个 100 x 100 像素的 BMP 图像。
with BmpImage(100, 100) as bmpImage:
# 使用简单的线性红黑渐变填充图像。
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:
# 您可以考虑使用 SetResolution 方法在一次调用中更新两个分辨率值。
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);
#输出可能如下所示:
#像素格式:Rgb24Bpp,使用的通道:8,8,8
#原始行大小(字节):1500
#位图压缩方式:Rgb
#位图宽度:500
#位图高度:375
#每像素位数:24
#水平分辨率(每英寸像素):0
#垂直分辨率(每英寸像素):0
#将分辨率值设置为 96 dpi
#水平分辨率(每英寸像素数):96.012
#垂直分辨率(每英寸像素数):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
# 创建一个 100 x 100 像素的 BMP 图像。
with BmpImage(100, 100) as bmpImage:
# 图像左上角到右下角的线性渐变。
brush = LinearGradientBrush(Point(0, 0), Point(bmpImage.width, bmpImage.height),
Color.red,
Color.green)
# 使用线性渐变画刷填充整个图像。
gr = Graphics(bmpImage)
gr.fill_rectangle(brush, bmpImage.bounds)
# 获取最接近的 8 位颜色调色板,覆盖尽可能多的像素,以便调色板图像
# 在视觉上几乎与没有调色板的 bmp 无法区分
palette = ColorPaletteHelper.get_close_image_palette(bmpImage, 256)
# 8 位调色板最多包含 256 种颜色。
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.")
# 输出如下:
# 带调色板的图像大小为 11078 字节。
# 不带调色板的图像大小为 40054 字节。
The example shows how to load a BmpImage from a file.
from aspose.imaging.fileformats.bmp import BmpImage
import os
directory = r"c:\temp"
# 从文件加载 BMP 图像。
# 如果需要,源像素将转换为 32 位每像素(bpp)格式。
with BmpImage(os.path.join(directory, "sample.bmp")) as bmp_image:
# 进行一些图像处理。
# 保存为另一个 BMP 文件。
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"
# 从文件加载 BMP 图像。
# 如果需要,源像素将转换为 24 位每像素(bpp)格式。
# 分辨率将被设置为 96 dpi。
with BmpImage(os.path.join(directory, "sample.bmp"), 24, BitmapCompression.RGB, 96.0, 96.0) as bmp_image:
# 进行一些图像处理。
# 保存为另一个 BMP 文件。
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"
# 从文件流加载 BMP 图像。
# 如果需要,源像素将转换为 32 位每像素(bpp)格式。
with open(os.path.join(directory, "sample.bmp"), "rb+") as stream:
with BmpImage(stream) as bmp_image:
# 进行一些图像处理。
# 保存为另一个 BMP 文件。
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"
# 从文件流加载 BMP 图像。
# 如果需要,源像素将转换为 24 位每像素(bpp)格式。
# 分辨率将被设置为 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:
# 进行一些图像处理。
# 保存为另一个 BMP 文件。
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"
# 创建一个新的 PNG 图像。
with PngOptions() as create_options:
create_options.source = StreamSource()
with aspycore.as_of(Image.create(create_options, 100, 100), RasterImage) as raster_image:
# 将整个 PNG 图像填充为红色。
gr = Graphics(raster_image)
brush = SolidBrush(Color.red)
gr.fill_rectangle(brush, raster_image.bounds)
# 基于 PNG 图像创建 BMP 图像。
# 如果需要,源像素将转换为 32 位每像素(bpp)格式。
with BmpImage(raster_image) as bmp_image:
# 保存为 BMP 文件
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"
# 创建一个新的 PNG 图像。
with PngOptions() as create_options:
create_options.source = StreamSource()
with aspycore.as_of(Image.create(create_options, 100, 100), RasterImage) as raster_image:
# 将整个 PNG 图像填充为红色。
gr = Graphics(raster_image)
brush = SolidBrush(Color.red)
gr.fill_rectangle(brush, raster_image.bounds)
# 基于 PNG 图像创建 BMP 图像。
# 如果需要,源像素将转换为 24 位每像素(bpp)格式。
# 分辨率将被设置为 96 dpi。
with BmpImage(raster_image, 24, BitmapCompression.RGB, 96.0, 96.0) as bmp_image:
# 保存为 BMP 文件
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"
# 创建一个 100 x 100 像素、32 位 BMP 图像。
with BmpImage(100, 100) as bmp_image:
# 将整幅图像填充为红色。
Graphics gr = Graphics(bmp_image)
brush = SolidBrush(Color.red)
gr.fill_rectangle(brush, bmp_image.bounds)
# 保存为 BMP 文件
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]
# 创建仅包含红色和绿色的单色调色板。
palette = ColorPalette.create_with_colors(paletterColors)
# 创建 100 x 100 像素的单色 1 位每像素(bpp)BMP 图像。
with BmpImage(100, 100, 1, palette) as bmp_image:
gr = Graphics(bmp_image)
# 将图像的上半部分填充为红色。
redBrush = SolidBrush(Color.red)
gr.fill_rectangle(redBrush, Rectangle(0, 0, bmp_image.width, bmp_image.height // 2))
# 将图像的下半部分填充为绿色。
greenBrush = SolidBrush(Color.green)
gr.fill_rectangle(greenBrush, Rectangle(0, bmp_image.height // 2, bmp_image.width, bmp_image.height // 2))
# 保存为 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]
# 创建仅包含红色和绿色的单色调色板。
palette = ColorPalette.create_with_colors(paletterColors)
# 创建 100 x 100 像素的单色 1 位每像素(bpp)BMP 图像。
with BmpImage(100, 100, 1, palette, BitmapCompression.RGB, 96.0, 96.0) as bmp_image:
gr = Graphics(bmp_image)
# 将图像的上半部分填充为红色。
redBrush = SolidBrush(Color.red)
gr.fill_rectangle(redBrush, Rectangle(0, 0, bmp_image.width, bmp_image.height // 2))
# 将图像的下半部分填充为绿色。
greenBrush = SolidBrush(Color.green)
gr.fill_rectangle(greenBrush, Rectangle(0, bmp_image.height // 2, bmp_image.width, bmp_image.height // 2))
# 保存为 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
# 创建一个 100 x 100 像素、32 位 BMP 图像。
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))
# 创建一个 100 x 100 像素、24 位 BMP 图像。
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))
# 通常,BMP 不支持 alpha 通道,因此输出将如下所示:
# FileFormat = BMP, RawDataFormat = Rgb32Bpp, 使用的通道: 8,8,8,8, HasAlpha = False
# FileFormat = BMP, RawDataFormat = Rgb24Bpp, 使用的通道: 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)
# 创建仅包含红色和绿色的单色调色板。
palette = ColorPalette.create_with_colors(paletterColors)
for compression in compressions:
# 创建 100 x 100 像素的 8 位每像素(bpp)BMP 图像。
with BmpImage(100, 100, 8, palette, compression, 0.0, 0.0) as bmp_image:
gr = Graphics(bmp_image)
# 将整幅图像填充为红色。
red_brush = SolidBrush(Color.red)
gr.fill_rectangle(red_brush, bmp_image.bounds)
# 将图像保存到内存流以获取输出图像大小。
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())
# 输出如下:
# ---------------------------------------------
# 压缩方式 = RGB
# 每像素位数 = 8
# 图像尺寸 =100 x 100
# 原始行大小 = 100
# 输出大小(字节) = 1178
# ---------------------------------------------
# 压缩 = RLE8
# 每像素位数 = 8
# 图像尺寸 =100 x 100
# 原始行大小 = 100
# 输出大小(字节) = 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)
# 获取 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)
{
# 使用 set_resolution 方法在一次调用中更新两个分辨率值。
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);
}
# 输出可能如下所示:
# 水平分辨率(每英寸像素):0
# 垂直分辨率(每英寸像素):0
# 将分辨率值设置为 96 dpi
# 水平分辨率(每英寸像素): 96.0
# 垂直分辨率(每英寸像素): 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)
#输出可能如下所示:
#显示位图所需的调色板颜色数量: 0
#位图中使用的调色板颜色数量: 0
#位图压缩: 0
#位图高度:375
#位图宽度:500
#位图原始数据大小(字节): 562500
#平面数量: 1
#位图的水平分辨率(每米像素): 0
#位图的垂直分辨率(每米像素): 0
#每像素位数:24
#额外位掩码:
#头部大小(字节): 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())