في هذا المثال الإرشادي ، سنرشدك عبر خطوات كيفية إضافة العلامة المائية في TIFF باستخدام C#. من السهل جدًا إدخال العلامة المائية في TIFF باستخدام C# عن طريق إجراء عدد قليل من استدعاءات API.
خطوات إدراج Tiff Watermark باستخدام C#
- قم بتثبيت حزمة Aspose.Imaging for .NET NuGet
- قم بتضمين مساحات الأسماء Aspose.Imaging و Aspose.Imaging.ImageOptions و Aspose.Imaging.Brushes
- استخدم طريقة Image.Load لتحميل Tiff وإضافة علامة Tiff المائية
- إنشاء كائنات فئات Graphics و Font و SolidBrush و StringFormat لتعيين خصائص الخط واللون والنصوص للعلامة المائية
- باستخدام Graphics حماية كائن فئة Tiff مع علامة مائية في C#
- حفظ الصورة الناتجة مع العلامة المائية Tiff
في الخطوات المذكورة أعلاه ، قمنا بتحميل صورة Tiff أولاً في الذاكرة باستخدام طريقة Load من فئة Image. ثم قمنا بتحديد سمات لتنسيق الخط والفرشاة والنص لحماية Tiff بالعلامة المائية في C#. أخيرًا ، نقوم بحفظ علامة Tiff المائية باستخدام C#.
كود لإدراج Tiff Watermark باستخدام C#
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"); | |
} | |
} | |
} | |
} |
باستخدام المثال أعلاه ، يمكنك بسهولة حماية Tiff باستخدام العلامة المائية في C# في مشاريع .NET بما في ذلك سطح مكتب Windows أو ويب ASP.NET أو تطبيقات وحدة التحكم.