実際の形状境界ポイントを取得する
コンテンツ
[
隠れる
]このチュートリアルでは、Aspose.Words for .NET を使用して、Word 文書内の図形の実際の境界をポイント (測定単位) で取得する方法について説明します。境界は、文書内の図形のサイズと位置を表します。
前提条件
このチュートリアルを実行するには、次のものが必要です。
- Aspose.Words for .NET ライブラリがインストールされています。
- C# と Word 文書を使用した Words Processing に関する基本的な知識。
ステップ1: 新しいドキュメントとDocumentBuilderを作成する
新しいインスタンスを作成するDocument
クラスとDocumentBuilder
ドキュメントを操作するオブジェクト。
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
ステップ2: 画像シェイプを挿入する
使用InsertImage
方法のDocumentBuilder
オブジェクトを使用して、ドキュメントに画像シェイプを挿入します。パラメータとして画像ファイルへのパスを指定します。
Shape shape = builder.InsertImage(ImagesDir + "Transparent background logo.png");
shape.AspectRatioLocked = false;
ステップ3: 実際の形状境界ポイントを取得する
図形のShapeRenderer
使用してGetShapeRenderer
メソッドを使用します。次に、BoundsInPoints
財産。
Console.Write("\nGets the actual bounds of the shape in points: ");
Console.WriteLine(shape.GetShapeRenderer().BoundsInPoints);
Aspose.Words for .NET を使用して実際の形状境界ポイントを取得するためのサンプル ソース コード
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.InsertImage(ImagesDir + "Transparent background logo.png");
shape.AspectRatioLocked = false;
Console.Write("\nGets the actual bounds of the shape in points: ");
Console.WriteLine(shape.GetShapeRenderer().BoundsInPoints);
これで完了です。Aspose.Words for .NET を使用して、Word 文書内の図形の実際の境界をポイント単位で取得できました。