XPS ファイル内の画像の操作 | .NET

XPSドキュメント内に画像を追加する

Aspose.Page for .NETには、 XpsPathクラスが用意されており、これを使用してXPSドキュメントに画像を追加できます。 XpsMatrixXpsImageBrushを作成し、 XpsDocumentを保存する必要があります。以下のコードスニペットは、XPSドキュメントに画像を追加するための完全な機能を示しています。

 1// Add image to XPS document.
 2
 3// Create new XPS Document
 4XpsDocument doc = new XpsDocument();
 5
 6string outputFileName = "AddImage_outXPS.xps";
 7
 8// Add Image
 9XpsPath path = doc.AddPath(doc.CreatePathGeometry("M 30,20 l 258.24,0 0,56.64 -258.24,0 Z"));
10//Creating a matrix is optional, it can be used for proper positioning
11path.RenderTransform = doc.CreateMatrix(0.7f, 0f, 0f, 0.7f, 0f, 20f);
12//Create Image Brush
13path.Fill = doc.CreateImageBrush(DataDir + "QL_logo_color.tif", new RectangleF(0f, 0f, 258.24f, 56.64f), new RectangleF(50f, 20f, 193.68f, 42.48f));
14// Save resultant XPS document
15doc.Save(OutputDir + outputFileName);
Example-AddImageXPS.cs hosted with ❤ by GitHub

XPSドキュメント内の画像の操作については、 Java および C++ を参照してください。


このコードを実行した結果は次のとおりです。

画像の追加

タイル画像の追加

このソリューションでは、 XpsPath クラスが提供されており、これを使用してXPSドキュメントに画像を追加できます。そのためには、まず XpsMatrixXpsImageBrush を作成し、 XpsTileMode.Tile モードを指定して XpsDocument を保存する必要があります。

次のコードスニペットは、XPS ドキュメントにタイル画像を追加するための完全な機能を示しています。

 1// Paint rectangle with tiled image (texture pattern) in XPS document.
 2
 3// Create new XPS Document
 4XpsDocument doc = new XpsDocument();
 5
 6string outputFileName = "AddTextureTilingPattern_outXPS.xps";
 7
 8// Tile image
 9// ImageBrush filled rectangle in the right top bellow
10XpsPath path = doc.AddPath(doc.CreatePathGeometry("M 10,160 L 228,160 228,305 10,305"));
11path.Fill = doc.CreateImageBrush(DataDir + "R08LN_NN.jpg", new RectangleF(0f, 0f, 128f, 96f), new RectangleF(0f, 0f, 64f, 48f));
12((XpsImageBrush)path.Fill).TileMode = XpsTileMode.Tile;
13path.Fill.Opacity = 0.5f;
14// Save resultant XPS document
15doc.Save(OutputDir + outputFileName);

XPSドキュメント内の画像の操作については、 Javaおよび C++を参照してください。


このコードを実行した結果は次のとおりです。

タイル画像の追加

サンプルとデータ ファイルは GitHub からダウンロードできます。

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.