Այս օրինակում, մենք ձեզ կքայլենք, թե ինչպես ավելացնել ջրի մակարդակի նշագիծ TIFF-ում՝ օգտագործելով C#: Շատ պարզ է ջրանիշը տեղադրել TIFF-ում C#-ի միջոցով՝ մի քանի API զանգեր կատարելով:
Tiff ջրանիշը 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 պատկերը հիշողության մեջ՝ օգտագործելով Image դասի Load մեթոդը: Այնուհետև մենք նշել ենք ատրիբուտներ տառատեսակի, վրձինի և տեքստի ձևաչափման համար՝ 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 վեբ կամ կոնսոլային հավելվածներ: