XImage

Overview

XImage is a class in Aspose.PDF FOSS for .NET. Inherits from: ImageXObject.

Image XObject wrapper exposing the public XImage surface.

This class provides 22 methods for working with XImage objects in .NET programs. Available methods include: AddStencilMask, Delete, DetectColorType, GetAlternativeText, GetColorType, GetDecodedData, GetJpegBytes, GetNameInCollection, GetRawData, GetRawImageData, IsTheSameObject, Rename, and 5 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, parsed from the image XObject’s /Metadata stream on first access (empty when the image carries no /Metadata).
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
Delete()Delete this image from the resources it was retrieved from.
Replace(stream: Stream)Replace this image’s data with the supplied image stream, keeping its resource name so existing content-stream references show the new pixels.
AddStencilMask(maskStream: Stream)Attach a stencil mask built from the given image 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 of the image.
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: Aspose.Pdf.Drawing.ImageFormat)Write the image re-encoded as the given ImageFormat.
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).
Save(path: string)Save the image to a file.
ToPng()Export the image as PNG bytes.

See Also

 English