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

NameTypeAccessDescription
NamestringRead/WriteThe resource name (e.g., “Im0”); writable on the derived type.
WidthintReadImage width in pixels.
HeightintReadImage height in pixels.
ContainsTransparencyboolReadWhether the image has an /SMask or /Mask entry indicating per-pixel transparency.
ImageMaskboolReadWhether the image is a 1-bit stencil mask (matches base IsImageMask).
FilterTypeImageFilterTypeReadThe compression filter applied to the image data.
GrayscaledSystem.Drawing.Image?ReadRender the image as a grayscale System.Drawing.Image.
MetadataMetadataReadXMP metadata attached to this image, when present.
BitsPerComponentintReadBits per component.
ColorSpacestring?ReadColor space name.
Filterstring?ReadThe filter used (e.g., “DCTDecode” for JPEG, “FlateDecode”).
IsJpegboolReadWhether this is a JPEG image (DCTDecode filter).
IsJpeg2000boolReadWhether this is a JPEG2000 image (JPXDecode filter).
HasSoftMaskboolReadWhether this image has a soft mask (alpha channel).
IsImageMaskboolReadWhether this is an image mask (stencil).
ComponentCountintReadNumber of color components based on the color space.

Methods

SignatureDescription
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.

See Also