このハウツーの例では、C#を使用してTIFFに透かしを追加する方法の手順を説明します。いくつかのAPI呼び出しを実行することにより、C#を使用してTIFFに透かしを挿入するのは非常に簡単です。
C#を使用してTiff透かしを挿入する手順
- Aspose.Imaging for .NETNuGetパッケージをインストールします
- Aspose.Imaging、Aspose.Imaging.ImageOptions、およびAspose.Imaging.Brushes名前空間を含める
- Image.Loadメソッドを使用してTiffを読み込み、Tiff透かしを追加します
- Graphics、Font、SolidBrush、およびStringFormatクラスオブジェクトをインスタンス化して、透かしのフォント、色、およびテキストのプロパティを設定します
- Graphicsクラスオブジェクトを使用して、C#の透かしでTiffを保護します
- Tiff透かしで出力画像を保存します
前述の手順では、ImageクラスのLoadメソッドを使用して、最初にTiff画像をメモリにロードしました。次に、C#の透かしでTiffを保護するために、フォント、ブラシ、テキストの書式設定の属性を指定しました。最後に、C#を使用してTiff透かしを保存しています。
C#を使用してTiff透かしを挿入するコード
using System; | |
using Aspose.Imaging; | |
using Aspose.Imaging.Brushes; | |
using Aspose.Imaging.ImageOptions; | |
namespace AddingTiffWatermark | |
{ | |
class TiffWatermark | |
{ | |
static void Main(string[] args) | |
{ | |
string PathForTiffFile = @"Y:\Downloads\"; | |
//Load the License file | |
License license = new License(); | |
license.SetLicense(PathForTiffFile + "Conholdate.Total.Product.Family.lic"); | |
// Use Image.Load to add tiff watermark using c# in Tiff file | |
using (var image = Aspose.Imaging.Image.Load(PathForTiffFile + "TiffToWatermark.tiff")) | |
{ | |
// Initialize Graphics class instance for loaded Tiff Image | |
Graphics graphics = new Aspose.Imaging.Graphics(image); | |
// Initialize SizeF to store image Size | |
Size size = graphics.Image.Size; | |
// Create an instance of Font to set the font Name, Size and Style | |
Font font = new Aspose.Imaging.Font("Arial", 24, | |
Aspose.Imaging.FontStyle.Bold); | |
// Instantiate SolidBrush and set Color and Opacity | |
SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(); | |
brush.Color = Aspose.Imaging.Color.Red; | |
brush.Opacity = 0; | |
// initialize an object of StringFormat class and | |
// set its various textual properties | |
StringFormat format = new Aspose.Imaging.StringFormat(); | |
format.Alignment = Aspose.Imaging.StringAlignment.Near; | |
format.FormatFlags = Aspose.Imaging.StringFormatFlags.FitBlackBox; | |
// Render the string on image with set font and brush | |
graphics.DrawString("PROTECTED", font, | |
brush, 0, 0, format); | |
// Save protected tiff with watermark in c# | |
image.Save(PathForTiffFile+"WatermarkedTiff.tiff"); | |
} | |
} | |
} | |
} |
上記の例を使用すると、Windowsデスクトップ、ASP.NET Web、またはコンソールアプリケーションを含む.NETプロジェクトのC#で透かしを使用してTiffを簡単に保護できます。