IXpsFixedPageWriter.AddImage Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Adds a new XpsImage to the current page.
Overloads
AddImage(String) |
Adds a new XpsImage with a specified MIME type to the current page. |
AddImage(XpsImageType) |
Adds a new XpsImage with a specified XpsImageType to the current page. |
Remarks
AddImage adds a new XpsImage to the document package and associates it with the current FixedPage.
AddImage(String)
Adds a new XpsImage with a specified MIME type to the current page.
public:
System::Windows::Xps::Packaging::XpsImage ^ AddImage(System::String ^ mimeType);
public System.Windows.Xps.Packaging.XpsImage AddImage (string mimeType);
abstract member AddImage : string -> System.Windows.Xps.Packaging.XpsImage
Public Function AddImage (mimeType As String) As XpsImage
Parameters
- mimeType
- String
The MIME type of the image to add.
Returns
The new image resource that was added to the page.
Exceptions
Dispose() has been called.
mimeType
is null
.
mimeType
is an empty string.
Examples
The following example shows how to use the AddImage method to add an image resource to a page.
// -------------------------- AddPageResources ----------------------------
Dictionary<System::String^,List<XpsResource^>^>^ AddPageResources (IXpsFixedPageWriter^ fixedPageWriter)
{
// Collection of all resources for this page.
// Key: "XpsImage", "XpsFont"
// Value: List of XpsImage or XpsFont
Dictionary<System::String^,List<XpsResource^>^>^ resources = gcnew Dictionary<System::String^,List<XpsResource^>^>();
// Collections of images and fonts used in the current page.
List<XpsResource^>^ xpsImages = gcnew List<XpsResource^>();
List<XpsResource^>^ xpsFonts = gcnew 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()
// -------------------------- 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()
' -------------------------- AddPageResources ----------------------------
Private Function AddPageResources(ByVal fixedPageWriter As IXpsFixedPageWriter) As Dictionary(Of String, List(Of XpsResource))
' Collection of all resources for this page.
' Key: "XpsImage", "XpsFont"
' Value: List of XpsImage or XpsFont
Dim resources As New Dictionary(Of String, List(Of XpsResource))()
' Collections of images and fonts used in the current page.
Dim xpsImages As New List(Of XpsResource)()
Dim xpsFonts As New List(Of XpsResource)()
Try
Dim xpsImage As XpsImage
Dim xpsFont As 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 xpsException As XpsPackagingException
Throw xpsException
End Try
End Function ' end:AddPageResources()
Remarks
AddImage adds a new XpsImage with a specified mimeType
to the document package and associates it with the current FixedPage.
See also
Applies to
AddImage(XpsImageType)
Adds a new XpsImage with a specified XpsImageType to the current page.
public:
System::Windows::Xps::Packaging::XpsImage ^ AddImage(System::Windows::Xps::Packaging::XpsImageType imageType);
public System.Windows.Xps.Packaging.XpsImage AddImage (System.Windows.Xps.Packaging.XpsImageType imageType);
abstract member AddImage : System.Windows.Xps.Packaging.XpsImageType -> System.Windows.Xps.Packaging.XpsImage
Public Function AddImage (imageType As XpsImageType) As XpsImage
Parameters
- imageType
- XpsImageType
The type of image to add to the page.
Returns
The new image resource that was added to the page.
Exceptions
Dispose() has been called.
Examples
The following example shows how to use the AddImage method to add an image resource to a page.
// -------------------------- AddPageResources ----------------------------
Dictionary<System::String^,List<XpsResource^>^>^ AddPageResources (IXpsFixedPageWriter^ fixedPageWriter)
{
// Collection of all resources for this page.
// Key: "XpsImage", "XpsFont"
// Value: List of XpsImage or XpsFont
Dictionary<System::String^,List<XpsResource^>^>^ resources = gcnew Dictionary<System::String^,List<XpsResource^>^>();
// Collections of images and fonts used in the current page.
List<XpsResource^>^ xpsImages = gcnew List<XpsResource^>();
List<XpsResource^>^ xpsFonts = gcnew 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()
// -------------------------- 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()
' -------------------------- AddPageResources ----------------------------
Private Function AddPageResources(ByVal fixedPageWriter As IXpsFixedPageWriter) As Dictionary(Of String, List(Of XpsResource))
' Collection of all resources for this page.
' Key: "XpsImage", "XpsFont"
' Value: List of XpsImage or XpsFont
Dim resources As New Dictionary(Of String, List(Of XpsResource))()
' Collections of images and fonts used in the current page.
Dim xpsImages As New List(Of XpsResource)()
Dim xpsFonts As New List(Of XpsResource)()
Try
Dim xpsImage As XpsImage
Dim xpsFont As 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 xpsException As XpsPackagingException
Throw xpsException
End Try
End Function ' end:AddPageResources()
Remarks
AddImage adds a new XpsImage with the specified XpsImageType to the document package and associates it with the current FixedPage.
For example, imageType
can be JpegImageType or PngImageType. to add a JPEG or PNG XpsImage, respectively.