Neste exemplo de instruções, orientaremos você nas etapas de como adicionar marca d’água em TIFF usando C#. É muito simples inserir marca d’água em TIFF usando C# realizando poucas chamadas de API.
Etapas para inserir marca d’água Tiff usando C#
- Instale o pacote NuGet Aspose.Imaging for .NET
- Inclua os namespaces Aspose.Imaging, Aspose.Imaging.ImageOptions e Aspose.Imaging.Brushes
- Use o método Image.Load para carregar o Tiff e adicionar a marca d’água Tiff
- Instancie objetos de classes Graphics, Font, SolidBrush e StringFormat para definir a fonte, a cor e as propriedades textuais da marca d’água
- Usando o objeto de classe Graphics, proteja o Tiff com marca d’água em C#
- Salvar imagem de saída com marca d’água Tiff
Nas etapas acima mencionadas, carregamos a imagem Tiff primeiro na memória usando o método Load da classe Image. Em seguida, especificamos atributos para formatação de fonte, pincel e texto para proteger Tiff com marca d’água em C#. Por fim, estamos salvando a marca d’água Tiff usando C#.
Código para inserir marca d’água 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"); | |
} | |
} | |
} | |
} |
Usando o exemplo acima, você pode proteger facilmente o Tiff com marca d’água em C# em seus projetos .NET, incluindo a área de trabalho do Windows, ASP.NET Web ou aplicativos de console.