C#でテキストにシャドウ効果を追加する方法
IronWordを使ってC#でテキストにシャドウ効果を追加するには、TextStyleオブジェクトを作成してShadowEffectプロパティを設定します。OuterShadow1などのプリセットを適用したり、ぼかし、距離、色などを調整したりすることで、文字に自然な奥行きを持たせられます。
シャドウ効果は、文字に奥行きを与えて目立たせる手法です。元のテキストの背後に、同じテキストを少しずらして描画することで影のように見せます。この影を調整すると、さまざまな視覚効果を得られます。
シャドウ効果は、テキストを目立たせる必要があるプロフェッショナルな文書、プレゼンテーション、レポートを作成する際に特に役立ちます。 PowerPointで空のプレゼンテーションを作成するように、IronWordを使用してWordドキュメントにプログラム的に高度なテキスト効果を追加することができます。 ライブラリは、迅速な実装のためのプリセットの影オプションと、独自のブランディング要件のための広範なカスタマイズ機能の両方を提供します。
クイックスタート:1行でプリセットのシャドウ効果を追加するIronWordでは、スタイルとシャドウを1行で設定した後、文書を保存するだけで、Word文書のテキストにシャドウ効果を適用できます。設定は最小限で済みます。本番環境で生成する文書に透かしが入らないよう、シャドウ効果を実装する前にライセンスキーが正しく設定されていることを確認してください。
-
1IronWord を NuGet Package Manager でインストールします
-
2このコード スニペットをコピーして実行します。
using IronWord; using IronWord.Models; WordDocument doc = new WordDocument(); TextStyle textStyle = new TextStyle(); textStyle.TextEffect = new TextEffect() { ShadowEffect = Shadow.OuterShadow1 }; Paragraph paragraph = new Paragraph(); Run textRun = new Run(new TextContent("Shadow Text")); textRun.Style = textStyle; paragraph.AddChild(textRun); doc.AddParagraph(paragraph); doc.SaveAs("shadow.docx");Imports IronWord Imports IronWord.Models Dim doc As New WordDocument() Dim textStyle As New TextStyle() textStyle.TextEffect = New TextEffect() With {.ShadowEffect = Shadow.OuterShadow1} Dim paragraph As New Paragraph() Dim textRun As New Run(New TextContent("Shadow Text")) textRun.Style = textStyle paragraph.AddChild(textRun) doc.AddParagraph(paragraph) doc.SaveAs("shadow.docx")Imports IronWord Imports IronWord.Models Dim doc As New WordDocument() Dim textStyle As New TextStyle() textStyle.TextEffect = New TextEffect() With {.ShadowEffect = Shadow.OuterShadow1} Dim paragraph As New Paragraph() Dim textRun As New Run(New TextContent("Shadow Text")) textRun.Style = textStyle paragraph.AddChild(textRun) doc.AddParagraph(paragraph) doc.SaveAs("shadow.docx") -
3実際の環境でテストするためにデプロイする
今日からご自身のプロジェクトでIronWordを使い始めるには、無料トライアルをお試しください。
テキストにシャドウ効果を追加する方法(5つのステップ)
- IronWordをインストールします。
Install-Package IronWord TextStyleを作成し、Shadow.OuterShadow1などのプリセットを使用してShadowEffectを設定します。TextContentを含むRunを作成し、そのRunにTextStyleを割り当てます。AddChildを使用してParagraphにRunを追加します。- 文書を保存します。
テキストにシャドウ効果を追加する方法
シャドウ効果を適用するには、TextStyleを作成し、そのTextEffectプロパティにShadowEffectを設定します。次にParagraphを作成し、TextContentを含むRunを作成します。TextStyleはRunに割り当てます(TextContentには割り当てません)。続いてAddChildでRunをParagraphに追加します。文書の階層は、Document → Paragraph → Run → TextContentの順です。
既存の文書生成ワークフローにも簡単に組み込めます。レポートの自動作成、証明書の生成、ブランドに合わせた文書の作成などで、シャドウ効果を使うと文字の見栄えを整えられます。IronWordのライセンスプランによる違いは、デプロイの範囲、開発者数、サポート期間に限られます。機能は共通で、開発、テスト、本番のいずれの環境でも、すべてのプランでシャドウ効果は同じように動作します。
どのプリセットシャドウ効果が利用可能ですか?
IronWordは、手動設定なしで迅速に導入できる1つの組み込みシャドウプリセットShadow.OuterShadow1を提供します。 他の視覚スタイル(微妙、大胆、劇的)には、カスタムShadowインスタンスを構築し、以下のカスタマイズセクションで説明されているように、Alignment、BlurRadius、DirectionAngle、DistanceFromText、SchemeColor、およびスケーリング/傾斜プロパティを直接設定します。
新機能や改善点を把握するために、変更履歴を定期的に確認してください。
プリセットとカスタムのシャドウ効果の使い分け
標準的な文書フォーマットと迅速な実装のために、プリセットシャドウを使用してください。 特定のブランディング要件や、プリセットにはない独自の視覚効果が必要な場合は、カスタムシャドウを選択してください。プリセットシャドウは、企業テンプレートや標準化されたレポートなど、複数のドキュメントで一貫性を保つことが重要なシナリオで威力を発揮します。
カスタムシャドウは、正確な色値や位置、ぼかし効果を指定するブランドガイドラインを扱う際に、非常に貴重なものとなります。 マーケティングチームは、すべての資料のビジュアルアイデンティティを維持するために、正確なシャドウの仕様を要求することがよくあります。 さらに、カスタムシャドウを使用することで、多層シャドウや特定の背景色を補完するシャドウなど、クリエイティブなエフェクトが可能になります。
基本的な実装パターンは何ですか?
WordDocumentを作成し、TextStyleをShadowEffectで構成し、スタイルをテキストに適用し、ドキュメントを保存します。 プリセットを使用する場合でも、カスタム設定を使用する場合でも、パターンは一貫しています。
using IronWord;
using IronWord.Models;
// Create new Word document
WordDocument doc = new WordDocument();
// Create and configure text style
TextStyle textStyle = new TextStyle();
textStyle.TextEffect = new TextEffect()
{
ShadowEffect = Shadow.OuterShadow1,
};
// Create paragraph
Paragraph paragraph = new Paragraph();
// Create run with text and style
Run textRun = new Run(new TextContent("Hello World"));
textRun.Style = textStyle;
// Add run to paragraph
paragraph.AddChild(textRun);
// Add paragraph to document
doc.AddParagraph(paragraph);
// Export new Word document
doc.SaveAs("shadowEffect.docx");using IronWord;
using IronWord.Models;
// Create new Word document
WordDocument doc = new WordDocument();
// Create and configure text style
TextStyle textStyle = new TextStyle();
textStyle.TextEffect = new TextEffect()
{
ShadowEffect = Shadow.OuterShadow1,
};
// Create paragraph
Paragraph paragraph = new Paragraph();
// Create run with text and style
Run textRun = new Run(new TextContent("Hello World"));
textRun.Style = textStyle;
// Add run to paragraph
paragraph.AddChild(textRun);
// Add paragraph to document
doc.AddParagraph(paragraph);
// Export new Word document
doc.SaveAs("shadowEffect.docx");Imports IronWord
Imports IronWord.Models
' Create new Word document
Dim doc As New WordDocument()
' Create and configure text style
Dim textStyle As New TextStyle()
textStyle.TextEffect = New TextEffect() With {
.ShadowEffect = Shadow.OuterShadow1
}
' Create paragraph
Dim paragraph As New Paragraph()
' Create run with text and style
Dim textRun As New Run(New TextContent("Hello World"))
textRun.Style = textStyle
' Add run to paragraph
paragraph.AddChild(textRun)
' Add paragraph to document
doc.AddParagraph(paragraph)
' Export new Word document
doc.SaveAs("shadowEffect.docx")Imports IronWord
Imports IronWord.Models
' Create new Word document
Dim doc As New WordDocument()
' Create and configure text style
Dim textStyle As New TextStyle()
textStyle.TextEffect = New TextEffect() With {
.ShadowEffect = Shadow.OuterShadow1
}
' Create paragraph
Dim paragraph As New Paragraph()
' Create run with text and style
Dim textRun As New Run(New TextContent("Hello World"))
textRun.Style = textStyle
' Add run to paragraph
paragraph.AddChild(textRun)
' Add paragraph to document
doc.AddParagraph(paragraph)
' Export new Word document
doc.SaveAs("shadowEffect.docx")
シャドウ効果のプロパティのカスタマイズ
定義済みのシャドウを適用できるほか、各プロパティを設定してシャドウ効果を柔軟にカスタマイズできます。以下のプロパティとその説明を参照してください。
ライセンスの拡張やアップグレードを検討しているチームにとって、カスタムシャドウ効果は、IronWordが企業向けの文書操作機能に力を入れている一例です。豊富なカスタマイズ機能により、導入後に文書処理のニーズが拡大しても対応できます。
影の位置を制御するプロパティはどれですか?
- Alignment: シャドウの配置を取得または設定します。
- DirectionAngle: シャドウ効果の方向角度を取得または設定します。 方向角は度で指定されます。
- DistanceFromText: テキストまたはオブジェクトからのシャドウ効果の距離を取得または設定します。 距離はポイント(1/72インチ)で指定されます。
これらのポジショニング・プロパティは、リアルなシャドウ効果を生み出すために連動します。 Alignmentプロパティは、テキストに対する影のアンカーポイントを決定し、DirectionAngleは光源の方向をシミュレートします。 DistanceFromTextは、ページ表面上のテキストの見かけの高さを制御します。 これらのプロパティを効果的に組み合わせることで、文書全体で一貫した光源から来るように見える影を作り出します。
シャドウの外観に影響するプロパティは何ですか?
- BlurRadius: シャドウ効果のぼかし半径を取得または設定します。 ぼかし半径はポイント(1/72インチ)で指定されます。
- SchemeColor: シャドウ効果のスキームカラーを取得または設定します。
外観に関するプロパティは、シャドウの見え方に直接影響します。BlurRadiusを小さくすると技術文書に向いた輪郭のはっきりしたシャドウになり、大きくするとデザイン用途に適した柔らかなシャドウになります。SchemeColorを使うと、シャドウを文書のカラーパレットに合わせ、全体の見た目を統一できます。
シャドウの拡大縮小とスキューの設定
- HorizontalScalingFactor: シャドウ効果の横方向の拡大縮小係数を取得または設定します。
- HorizontalSkewAngle: シャドウ効果の横方向のスキュー角度を取得または設定します。 傾斜角は度で指定されます。
- VerticalScalingFactor: シャドウ効果の縦方向の拡大縮小係数を取得または設定します。
- VerticalSkewAngle: シャドウ効果の縦方向のスキュー角度を取得または設定します。 傾斜角は度で指定されます。
スケーリングとスキューのプロパティは、テキストに立体感を加えるパースペクティブ効果を可能にします。 HorizontalScalingFactorとVerticalScalingFactorは影を伸縮し、さまざまな視点効果をシミュレートします。 斜めの角度を使用すると、イタリック体のようなシャドウ効果を作成したり、角度のある表面に投影される影をシミュレートしたりできるため、ドキュメントに洗練された視覚的奥行きが加わります。
一般的なプロパティ値の範囲は何ですか?
BlurRadiusは通常0〜10ポイントの範囲、DirectionAngleは0〜360度の範囲であり、スケーリング係数はパーセンテージ値を使用します(100 = 通常のサイズ)。 DistanceFromTextは通常1-5ポイントの範囲が微妙な効果に最適です。
これらの範囲を把握しておくと、用途に合った設定値をすばやく選べます。業務文書では小さめの値(BlurRadius: 2~4、DistanceFromText: 1~2)を指定すると、読みやすさを保ちながら見た目に変化を付けられます。デザイン用途で印象を強めたい場合は、大きめの値(BlurRadius: 8~10、DistanceFromText: 4~6)を指定します。プリンターの性能や画面の解像度によってシャドウの見え方が変わるため、実際に使用する出力方法で文書をテストしてください。
using IronWord;
using IronWord.Models;
using IronWord.Models.Enums;
// Create new Word document
WordDocument doc = new WordDocument();
// Create and configure text style
TextStyle textStyle = new TextStyle();
textStyle.TextEffect = new TextEffect()
{
ShadowEffect = new Shadow()
{
Alignment = RectangleAlignmentValues.BottomLeft,
BlurRadius = 5,
DirectionAngle = 45,
DistanceFromText = 3,
HorizontalScalingFactor = 100,
VerticalScalingFactor = 100,
HorizontalSkewAngle = 0,
SchemeColor = IronWord.Models.Color.Aqua,
VerticalSkewAngle = 0,
},
};
// Create paragraph
Paragraph paragraph = new Paragraph();
// Create run with text and style
Run textRun = new Run(new TextContent("Customized shadow"));
textRun.Style = textStyle;
// Add run to paragraph
paragraph.AddChild(textRun);
// Add paragraph to document
doc.AddParagraph(paragraph);
// Export new Word document
doc.SaveAs("customizedShadowEffect.docx");using IronWord;
using IronWord.Models;
using IronWord.Models.Enums;
// Create new Word document
WordDocument doc = new WordDocument();
// Create and configure text style
TextStyle textStyle = new TextStyle();
textStyle.TextEffect = new TextEffect()
{
ShadowEffect = new Shadow()
{
Alignment = RectangleAlignmentValues.BottomLeft,
BlurRadius = 5,
DirectionAngle = 45,
DistanceFromText = 3,
HorizontalScalingFactor = 100,
VerticalScalingFactor = 100,
HorizontalSkewAngle = 0,
SchemeColor = IronWord.Models.Color.Aqua,
VerticalSkewAngle = 0,
},
};
// Create paragraph
Paragraph paragraph = new Paragraph();
// Create run with text and style
Run textRun = new Run(new TextContent("Customized shadow"));
textRun.Style = textStyle;
// Add run to paragraph
paragraph.AddChild(textRun);
// Add paragraph to document
doc.AddParagraph(paragraph);
// Export new Word document
doc.SaveAs("customizedShadowEffect.docx");Imports IronWord
Imports IronWord.Models
Imports IronWord.Models.Enums
' Create new Word document
Dim doc As New WordDocument()
' Create and configure text style
Dim textStyle As New TextStyle()
textStyle.TextEffect = New TextEffect() With {
.ShadowEffect = New Shadow() With {
.Alignment = RectangleAlignmentValues.BottomLeft,
.BlurRadius = 5,
.DirectionAngle = 45,
.DistanceFromText = 3,
.HorizontalScalingFactor = 100,
.VerticalScalingFactor = 100,
.HorizontalSkewAngle = 0,
.SchemeColor = IronWord.Models.Color.Aqua,
.VerticalSkewAngle = 0
}
}
' Create paragraph
Dim paragraph As New Paragraph()
' Create run with text and style
Dim textRun As New Run(New TextContent("Customized shadow"))
textRun.Style = textStyle
' Add run to paragraph
paragraph.AddChild(textRun)
' Add paragraph to document
doc.AddParagraph(paragraph)
' Export new Word document
doc.SaveAs("customizedShadowEffect.docx")Imports IronWord
Imports IronWord.Models
Imports IronWord.Models.Enums
' Create new Word document
Dim doc As New WordDocument()
' Create and configure text style
Dim textStyle As New TextStyle()
textStyle.TextEffect = New TextEffect() With {
.ShadowEffect = New Shadow() With {
.Alignment = RectangleAlignmentValues.BottomLeft,
.BlurRadius = 5,
.DirectionAngle = 45,
.DistanceFromText = 3,
.HorizontalScalingFactor = 100,
.VerticalScalingFactor = 100,
.HorizontalSkewAngle = 0,
.SchemeColor = IronWord.Models.Color.Aqua,
.VerticalSkewAngle = 0
}
}
' Create paragraph
Dim paragraph As New Paragraph()
' Create run with text and style
Dim textRun As New Run(New TextContent("Customized shadow"))
textRun.Style = textStyle
' Add run to paragraph
paragraph.AddChild(textRun)
' Add paragraph to document
doc.AddParagraph(paragraph)
' Export new Word document
doc.SaveAs("customizedShadowEffect.docx")
よくある質問
IronWordを使用してテキストにシャドウ効果を追加する方法は?
IronWordを使用してシャドウ効果を追加するには、ShadowEffectプロパティを持つTextStyleオブジェクトを作成します。OuterShadow1のようなプリセットシャドウを適用するか、ぼかし、距離、色などのプロパティをカスタマイズしてWordドキュメントを強化できます。
C#のWord文書でシャドウ効果を実装する手順は何ですか?
まず、IronWordをインストールし、その後TextStyleを作成し、ShadowEffectを構成します。TextContentを持つRunを作成し、TextStyleをRunに適用し、RunをParagraphに追加し、最後に文書を保存します。
IronWordが提供するプリセットシャドウ効果オプションは何ですか?
IronWordには1つのプリセットシャドウ効果、Shadow.OuterShadow1が含まれており、複雑な設定なしで迅速に実装できます。他のスタイルのためには、カスタムシャドウ設定を作成できます。
IronWordでプリセットシャドウ効果をいつ使用すべきですか?
標準の文書フォーマットや、複数の文書にわたる一貫性が重要な場合、特に企業のテンプレートなどで、迅速な実装のためにプリセットシャドウ効果を使用します。
IronWordでシャドウ効果はどのようにカスタマイズできますか?
シャドウ効果は、Alignment、BlurRadius、DirectionAngle、DistanceFromText、SchemeColor、スケーリングおよびスキュー係数を設定することによりカスタマイズでき、個別の視覚効果を提供します。
IronWordでブランディングのためにシャドウ効果を使用できますか?
はい、IronWordのカスタムシャドウ効果は、正確な色の値や位置、ぼかし効果を調整することで特定のブランディング要件を満たし、ブランドガイドラインを維持します。
シャドウ効果の位置を制御するプロパティは何ですか?
シャドウ効果の位置は、Alignment、DirectionAngle、DistanceFromTextなどのプロパティによって制御され、リアルな光源をシミュレートするのに役立ちます。
`BlurRadius`プロパティのシャドウ効果における重要性は何ですか?
BlurRadiusプロパティは、シャドウのエッジのシャープさを決定し、低い値は鮮明なシャドウを生成し、高い値は拡散された柔らかいシャドウ効果を提供します。
IronWordでシャドウのスケーリングとスキューのプロパティがテキストにどのように影響しますか?
HorizontalScalingFactor、VerticalScalingFactor、およびスキュー角度などのスケーリングとスキューのプロパティにより、テキストに次元性と洗練を加えるための遠近効果を可能にします。
シャドウ効果プロパティの一般的な値の範囲は何ですか?
BlurRadiusは通常0-10ポイントの範囲、DirectionAngleは0-360度の範囲で、距離とスケーリング係数はさまざまであり、異なる文書タイプでプロフェッショナルな結果を保証します。
Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。