이 방법 예에서는 C#을 사용하여 TIFF에 워터마크를 추가하는 방법을 단계별로 안내합니다. 몇 가지 API 호출을 수행하여 C#을 사용하여 TIFF에 워터마크를 삽입하는 것은 매우 간단합니다.
C#을 사용하여 Tiff 워터마크를 삽입하는 단계
- Aspose.Imaging for .NET NuGet 패키지 설치
- 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 웹 또는 콘솔 응용 프로그램을 포함한 .NET 프로젝트에서 C#의 워터마크로 Tiff를 쉽게 보호할 수 있습니다.