画像の操作| C ++ APIソリューション
XPSドキュメント内に画像を追加します
画像を追加します
C ++ APIのAsopse.Pageを使用すると、XPSドキュメントを作成/読み取り、画像を追加できます。 これは、 XPSMATRIXおよび XPSIMAGEBRUSHを作成して、XPSファイルに画像を追加することで実行できます。 XPSドキュメントに画像を追加するには、次の手順を使用します。
- XPSDocumentクラスのオブジェクトを作成します
- XPSPATHを作成して、定義されたパスジオメトリを使用します
- set_renderTransformを使用してパスのレンダリング変換を設定します
- set_fillを使用して、creared画像ブラシでパスを埋める
- Save the document to disc using the Save method
1For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C
2// Create new XPS Document
3System::SharedPtr<XpsDocument> doc = System::MakeObject<XpsDocument>();
4// Add Image
5System::SharedPtr<XpsPath> path = doc->AddPath(doc->CreatePathGeometry(u"M 30,20 l 258.24,0 0,56.64 -258.24,0 Z"));
6//Creating a matrix is optional, it can be used for proper positioning
7path->set_RenderTransform(doc->CreateMatrix(0.7f, 0.f, 0.f, 0.7f, 0.f, 20.f));
8//Create Image Brush
9path->set_Fill(doc->CreateImageBrush(dataDir() + u"QL_logo_color.tif", System::Drawing::RectangleF(0.f, 0.f, 258.24f, 56.64f), System::Drawing::RectangleF(50.f, 20.f, 193.68f, 42.48f)));
10// Save resultant XPS document
11doc->Save(outDir() + u"AddImage_out.xps");
タイル張りの画像を追加します
ソリューションは xpspathクラスを提供し、XPSドキュメントに画像を追加できます。 上記のようにマトリックスとImageBrushを作成した後、 xpstilemode。タイルモードを指定します。 ImageBrushの場合は、Opacity値を0から1に設定できます。 次に、ドキュメントを保存します。 次のコードスニペットは、XPSドキュメントにタイル張りの画像を追加する完全な機能を示しています。
1For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C
2// Create new XPS Document
3System::SharedPtr<XpsDocument> doc = System::MakeObject<XpsDocument>();
4// Tile image
5// ImageBrush filled rectangle in the right top bellow
6System::SharedPtr<XpsPath> path = doc->AddPath(doc->CreatePathGeometry(u"M 10,160 L 228,160 228,305 10,305"));
7path->set_Fill(doc->CreateImageBrush(dataDir() + u"R08LN_NN.jpg", System::Drawing::RectangleF(0.f, 0.f, 128.f, 96.f), System::Drawing::RectangleF(0.f, 0.f, 64.f, 48.f)));
8(System::DynamicCast<Aspose::Page::Xps::XpsModel::XpsImageBrush>(path->get_Fill()))->set_TileMode(Aspose::Page::Xps::XpsModel::XpsTileMode::Tile);
9path->get_Fill()->set_Opacity(0.5f);
10// Save resultant XPS document
11doc->Save(outDir() + u"AddTiledImage_out.xps");