
Vattenmärken spelar en viktig roll i att hävda ägande av bilder och förhindra obehörig användning eller förfalskning. Genom att implementera en automatiserad vattenmärkning funktion i din webb eller skrivbordsapplikationer kan avsevärt förbättra din bildsäkerhet. I den här artikeln kommer vi att leda dig genom processen att lägga vattenmärken till bilderna programmerat med C#. Dessutom kommer du att lära dig hur man lägger till ett vattenmärke till PDF-filer med C# för att ytterligare säkra dina dokument.
Tabell av innehåll
- C# API för att lägga till vattenmärke till bilder
- Lägg till vattenmärke till en bild i C#
- Lägg till Diagonal Watermark till bilder i C#
- Få gratis API licens
C# API för att lägga till vattenmärke till bilder
To add watermarks to images, we will utilize the Aspose.Imaging för .NET. This powerful image processing API supports various formats, including PNG, JPEG, and BMP, making image manipulation straightforward. You can either Ladda ner API binära or install it via NuGet using the following command:
PM> Install-Package Aspose.Imaging
Lägg till vattenmärke till en bild i C#
Följ dessa steg för att lägga till ett vattenmärke till en bild med C#:
- Load the image using the Bilderna class.
- Create an instance of the Grafiken class, initializing it with the Bilderna object.
- Define the font family, size, and style using the Font class.
- Create a För SolidBrush instance to set properties like color.
- Instantiate the Stringformat class to manage text alignment.
- Add the watermark to the image using the Graphics.DrawString(String, Font, SolidBrush, 0, 0, StringFormat) method.
- Save the image using the Bilder från String (Save) method.
Här är ett kodprov som visar hur man lägger till ett vattenmärke till en bild i C#:

C# Lägg till Diagonal vattenmärke till bilder
Ibland appliceras vattenmärken diagonalt över bilder för en mer distinktiv effekt. Aspose.Imaging för .NET API gör att du kan rotera vattenmärken text för att uppnå detta. Här är hur man lägger till en diagonal vattenmärke:
- Load the image using the Bilderna class.
- Create a Grafiken instance initialized with the Bilderna object.
- Define the font family, size, and style with the Font class.
- Create a För SolidBrush instance to set properties like color.
- Instantiate a Stringformat object for text alignment.
- Create a Matrix instance to set the transformation angle.
- Assign the Matrix object to the Grafiken - Transformation property.
- Add the watermark using the Graphics.DrawString(String, Font, SolidBrush, 0, 0, StringFormat) method.
- Save the image using the Bilder från String (Save) method.
Här är ett kodprov som illustrerar hur man lägger till ett diagonalt vattenmärke till bilder med C#:

Ange vattenmärke på bilder med en gratis licens
You can Få en gratis tillfällig licens to insert watermarks on images without any evaluation limitations.
slutsatser
In this article, you learned how to add a watermark to images in C#. You also discovered how to rotate watermark text and how to add a watermark in PDF using C#. For further information about the C# image processing API, please refer to the Dokumentation. If you have any questions or need assistance, feel free to reach out via our Forumet.
Se även
More in this category
- C# Animation Maker Plugin: Skapa fantastiska animationer med Aspose.Imaging
- Aspose.Imaging Image Effect Plugin: Förbättra dina bilder med avancerade filter
- Sammanfoga bilder i C# med $99 Aspose.Imaging Image Merger-plugin
- Prisvärd företagsbildbehandling med Aspose.Imaging
- Prisvärd bildrotation i C# | Aspose.Imaging $99-plugin