كيفية إضافة علامة مائية في Tiff باستخدام C#

في هذا المثال الإرشادي ، سنرشدك عبر خطوات كيفية إضافة العلامة المائية في TIFF باستخدام C#. من السهل جدًا إدخال العلامة المائية في TIFF باستخدام C# عن طريق إجراء عدد قليل من استدعاءات API.

خطوات إدراج Tiff Watermark باستخدام C#

  1. قم بتثبيت حزمة Aspose.Imaging for .NET NuGet
  2. قم بتضمين مساحات الأسماء Aspose.Imaging و Aspose.Imaging.ImageOptions و Aspose.Imaging.Brushes
  3. استخدم طريقة Image.Load لتحميل Tiff وإضافة علامة Tiff المائية
  4. إنشاء كائنات فئات Graphics و Font و SolidBrush و StringFormat لتعيين خصائص الخط واللون والنصوص للعلامة المائية
  5. باستخدام Graphics حماية كائن فئة Tiff مع علامة مائية في C#
  6. حفظ الصورة الناتجة مع العلامة المائية 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 أو تطبيقات وحدة التحكم.

 عربي