XImage
Overview
XImage is a class in Aspose.PDF FOSS for .NET.
Inherits from: ImageXObject.
Image XObject wrapper exposing the XImage public surface.
This class provides 18 methods for working with XImage objects in .NET programs.
Available methods include: AddStencilMask, DetectColorType, GetAlternativeText, GetColorType, GetDecodedData, GetJpegBytes, GetNameInCollection, GetRawData, GetRawImageData, IsTheSameObject, Rename, Save, and 3 additional methods.
All public members are accessible to any .NET application after installing the Aspose.PDF FOSS for .NET package.
Properties: BitsPerComponent, ColorSpace, ComponentCount, ContainsTransparency, Filter, FilterType, and 10 more.
Properties
| Name | Type | Access | Description |
|---|---|---|---|
Name | string | Read/Write | The resource name (e.g., “Im0”); writable on the derived type. |
Width | int | Read | Image width in pixels. |
Height | int | Read | Image height in pixels. |
ContainsTransparency | bool | Read | Whether the image has an /SMask or /Mask entry indicating per-pixel transparency. |
ImageMask | bool | Read | Whether the image is a 1-bit stencil mask (matches base IsImageMask). |
FilterType | ImageFilterType | Read | The compression filter applied to the image data. |
Grayscaled | System.Drawing.Image? | Read | Render the image as a grayscale System.Drawing.Image. |
Metadata | Metadata | Read | XMP metadata attached to this image, when present. |
BitsPerComponent | int | Read | Bits per component. |
ColorSpace | string? | Read | Color space name. |
Filter | string? | Read | The filter used (e.g., “DCTDecode” for JPEG, “FlateDecode”). |
IsJpeg | bool | Read | Whether this is a JPEG image (DCTDecode filter). |
IsJpeg2000 | bool | Read | Whether this is a JPEG2000 image (JPXDecode filter). |
HasSoftMask | bool | Read | Whether this image has a soft mask (alpha channel). |
IsImageMask | bool | Read | Whether this is an image mask (stencil). |
ComponentCount | int | Read | Number of color components based on the color space. |
Methods
| Signature | Description |
|---|---|
AddStencilMask(maskStream: Stream) | Attach a stencil mask from a stream. |
DetectColorType(bmp: System.Drawing.Bitmap) | Detect whether a bitmap is grayscale, RGB, or CMYK by sampling its pixels. |
GetAlternativeText(page: Page) | Alternative-text accessor — returns alt strings declared for this image in the page’s structure tree. |
GetColorType() | Detect the colour family from the image’s /ColorSpace entry. |
GetNameInCollection() | The resource name as registered in the page’s XObject dictionary. |
GetRawImageData() | Get a copy of the raw (encoded) image data as a seekable MemoryStream. |
IsTheSameObject(image: XImage) | Reference equality against another XImage. |
Rename(name: string) | Rename the image’s resource entry. |
Save(stream: Stream) | Write the image bytes to a stream. |
Save(stream: Stream, format: System.Drawing.Imaging.ImageFormat) | Write the image bytes to a stream re-encoded as format. |
Save(stream: Stream, format: System.Drawing.Imaging.ImageFormat, resolution: int) | Write the image bytes to a stream re-encoded as format at the supplied resolution. |
Save(stream: Stream, resolution: int) | Write the image bytes to a stream at the supplied resolution. |
ToStream() | Return the image bytes as a seekable stream. |
TrySetAlternativeText(alternativeText: string, page: Page) | Attach alternative text to this image via the page’s structure tree. |
GetRawData() | Get the raw (encoded) image data. |
GetDecodedData() | Get the decoded image data (filters removed). |
GetJpegBytes() | For JPEG images, returns the raw JPEG bytes (ready to write as .jpg file). |
ToPng() | Export the image as PNG bytes. |