วิธีเพิ่มลายน้ำใน Tiff โดยใช้ C#

ในตัวอย่างวิธีการนี้ เราจะแนะนำขั้นตอนสำหรับการเพิ่มลายน้ำใน TIFF โดยใช้ C# การแทรกลายน้ำใน TIFF โดยใช้ C# ทำได้ง่ายมากโดยการเรียกใช้ API เพียงไม่กี่ครั้ง

ขั้นตอนในการใส่ลายน้ำ Tiff โดยใช้ 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 ของคลาสอิมเมจ จากนั้นเราได้ระบุแอตทริบิวต์สำหรับการจัดรูปแบบ Font, Brush และ Text เพื่อป้องกัน Tiff ด้วยลายน้ำใน C# สุดท้าย เรากำลังบันทึกลายน้ำ Tiff โดยใช้ C#

รหัสเพื่อใส่ลายน้ำ Tiff โดยใช้ 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 หรือแอปพลิเคชันคอนโซล

 ไทย