XpsImage Class

Definition

Represents an image in an XpsDocument.

C#
public class XpsImage : System.Windows.Xps.Packaging.XpsResource
Inheritance

Examples

The following example shows how to add images to an XpsDocument.

C#
// -------------------------- AddPageResources ----------------------------
private Dictionary<string, List<XpsResource>>
        AddPageResources(IXpsFixedPageWriter fixedPageWriter)
{
    // Collection of all resources for this page.
    //   Key: "XpsImage", "XpsFont"
    //   Value: List of XpsImage or XpsFont
    Dictionary<string, List<XpsResource>> resources =
        new Dictionary<string, List<XpsResource>>();

    // Collections of images and fonts used in the current page.
    List<XpsResource> xpsImages = new List<XpsResource>();
    List<XpsResource> xpsFonts  = new List<XpsResource>();

    try
    {
        XpsImage xpsImage;
        XpsFont  xpsFont;

        // Add, Write, and Commit image1 to the current page.
        xpsImage = fixedPageWriter.AddImage(XpsImageType.JpegImageType);
        WriteToStream(xpsImage.GetStream(), image1);
        xpsImage.Commit();
        xpsImages.Add(xpsImage);    // Add image1 as a required resource.

        // Add, Write, and Commit font 1 to the current page.
        xpsFont = fixedPageWriter.AddFont();
        WriteObfuscatedStream(
            xpsFont.Uri.ToString(), xpsFont.GetStream(), font1);
        xpsFont.Commit();
        xpsFonts.Add(xpsFont);      // Add font1 as a required resource.

        // Add, Write, and Commit image2 to the current page.
        xpsImage = fixedPageWriter.AddImage(XpsImageType.TiffImageType);
        WriteToStream(xpsImage.GetStream(), image2);
        xpsImage.Commit();
        xpsImages.Add(xpsImage);    // Add image2 as a required resource.

        // Add, Write, and Commit font2 to the current page.
        xpsFont = fixedPageWriter.AddFont(false);
        WriteToStream(xpsFont.GetStream(), font2);
        xpsFont.Commit();
        xpsFonts.Add(xpsFont);      // Add font2 as a required resource.

        // Return the image and font resources in a combined collection.
        resources.Add("XpsImage", xpsImages);
        resources.Add("XpsFont", xpsFonts);
        return resources;
    }
    catch (XpsPackagingException xpsException)
    {
        throw xpsException;
    }
}// end:AddPageResources()

Remarks

The XpsImage class has no public constructor.

Use the AddImage method to add an image and obtain a reference to it in a new document.

Use the GetImage method to obtain an image reference in an existing document.

Based on settings of XpsSerializationManager and XpsPackagingPolicy, such as FontSubsetterCommitPolicies and PackageInterleavingOrder, the flush operation of the Commit method of the XpsImage class may be delayed until the complete XpsDocument is closed.

Properties

Uri

Gets or sets the uniform resource identifier (URI) of the part.

(Inherited from XpsPartBase)

Methods

Commit()

Commits all changes and flushes the resource to the document package.

(Inherited from XpsResource)
Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetStream()

When overridden in a derived class, returns the I/O stream for reading or writing the resource.

(Inherited from XpsResource)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
RelativeUri(Uri)

Returns the URI of the resource that is relative to a specified absolute URI.

(Inherited from XpsResource)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

IDisposable.Dispose()

This member supports the Windows Presentation Foundation infrastructure and is not intended to be used directly from your code.

(Inherited from XpsResource)

Applies to

Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

See also