In questo esempio di procedura, ti guideremo attraverso i passaggi su come aggiungere filigrana in TIFF utilizzando C#. È molto semplice inserire la filigrana in TIFF utilizzando C# eseguendo alcune chiamate API.
Passaggi per inserire la filigrana Tiff usando C#
- Installa Aspose.Imaging for .NET pacchetto NuGet
- Includi spazi dei nomi Aspose.Imaging, Aspose.Imaging.ImageOptions e Aspose.Imaging.Brushes
- Usa il metodo Image.Load per caricare il Tiff e aggiungere la filigrana Tiff
- Istanziare oggetti classi Graphics, Font, SolidBrush e StringFormat per impostare il carattere, il colore e le proprietà testuali della filigrana
- Utilizzando Graphics l’oggetto classe protegge Tiff con filigrana in C#
- Salva immagine di output con filigrana Tiff
Nei passaggi sopra menzionati, abbiamo prima caricato l’immagine Tiff in memoria usando il metodo Load della classe Image. Quindi abbiamo specificato gli attributi per la formattazione di caratteri, pennelli e testo per proteggere Tiff con filigrana in C#. Infine, stiamo salvando la filigrana Tiff usando C#.
Codice per inserire la filigrana Tiff usando 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"); | |
} | |
} | |
} | |
} |
Utilizzando l’esempio precedente, puoi facilmente proteggere Tiff con filigrana in C# nei tuoi progetti .NET, inclusi desktop Windows, Web ASP.NET o applicazioni console.