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

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

Aspose.Page for Java には、XPS ドキュメントに画像を追加できる XpsPath クラスが用意されています。Matrix と ImageBrush を作成し、XpsDocument を保存する必要があります。以下のコード スニペットは、XPS ドキュメントに画像を追加する機能のすべてを示しています。

 1// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-Java
 2// The path to the documents directory.
 3String dataDir = Utils.getDataDir();
 4// Create new XPS Document
 5XpsDocument doc = new XpsDocument();
 6// Add Image
 7XpsPath path = doc.addPath(doc.createPathGeometry("M 30,20 l 258.24,0 0,56.64 -258.24,0 Z"));
 8// Creating a matrix is optional, it can be used for proper positioning
 9path.setRenderTransform(doc.createMatrix(0.7f, 0f, 0f, 0.7f, 0f, 20f));
10// Create Image Brush
11path.setFill(doc.createImageBrush(dataDir + "QL_logo_color.tif", new Rectangle2D.Double(0f, 0f, 258.24f, 56.64f), new Rectangle2D.Double(50f, 20f, 193.68f, 42.48f)));
12// Save resultant XPS document
13doc.save(dataDir + "AddImage_out.xps");

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


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

画像の追加

タイル画像の追加

Aspose.Page for Java には、XPS ドキュメントに画像を追加できる XpsPath クラスが用意されています。Matrix と ImageBrush を作成し、setTileMode(XpsTileMode.Tile) モードで XpsDocument を保存する必要があります。次のコード スニペットは、XPS ドキュメントにタイル画像を追加するための完全な機能を示しています。

 1// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-Java
 2// The path to the documents directory.
 3String dataDir = Utils.getDataDir();
 4
 5// Create new XPS Document
 6XpsDocument doc = new XpsDocument();
 7// Tile image
 8// ImageBrush filled rectangle in the right top bellow
 9XpsPath path = doc.addPath(doc.createPathGeometry("M 10,160 L 228,160 228,305 10,305"));
10path.setFill(doc.createImageBrush(dataDir +  "R08LN_NN.jpg",
11                                new Rectangle2D.Float(0f, 0f, 128f, 96f), new Rectangle2D.Float(0f, 0f, 64f, 48f)));
12((XpsImageBrush)path.getFill()).setTileMode(XpsTileMode.Tile);
13path.getFill().setOpacity(0.5f);
14// Save resultant XPS document
15doc.save(dataDir + "AddTiledImage_out.xps");

.NET および C++ で XPS ドキュメント内の画像を操作する方法をご覧ください。


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

タイル画像の追加

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

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.