<summary>
Create a picture watermark on a picture
</summary>
<param name= "Path" > Original server picture Path </param>
<param name= "PATH_SYP" > Generated picture watermark with picture path </param>
<param name= "PATH_SYPF" > Watermark picture Path </param>
public static void Addwaterpic (String Path, String path_syp, String path_sypf,int x=0,int y=0)
{
using (Image srcimg = Image.FromFile (Path))
{
To load a watermark file into memory
using (Image WaterMark = Image.FromFile (PATH_SYPF))
{
Instantiate a piece of canvas
using (Graphics g = graphics.fromimage (srcimg))
{
if (x = = 0)
{
x = (int) ((double) srcimg.width-(double) watermark.width)/2);
}
if (y = = 0)
{
y = (int) ((double) Srcimg.height-((double) WATERMARK.HEIGHT/2))/2);
}
Write text
g.DrawString ("17CN Mall All rights reserved ...", New Font ("Microsoft Yahei"), New SolidBrush (color.red), 20,20);
Painting pictures
Given a watermark by picture size
if (Srcimg.width > 100000000)
//{
PATH_SYPF = PATH_SYPF. Replace ("Logo_1.png", "logo_1.png");
//}
else if (Srcimg.width > 500000)
//{
PATH_SYPF = PATH_SYPF. Replace ("Logo_1.png", "logo_1.png");
//}
Watermark compression when the width of the watermark is greater than the width of the image
if (Watermark.width > Srcimg.width)
{
x = 0;
int waterh = (int) (double) Srcimg.width/(Double) watermark.width * (double) watermark.height);
G.drawimage (Watermark.getthumbnailimage (Srcimg.width,waterh, NULL, IntPtr.Zero), New Rectangle (x, Y, Watermark.width , Watermark.height), 0, 0, watermark.width, Watermark.height, GraphicsUnit.Pixel);
}
Else
{
G.drawimage (WaterMark, New Rectangle (x, Y, Watermark.width, Watermark.height), 0, 0, watermark.width, Watermark.height, GraphicsUnit.Pixel);
}
Srcimg.save (PATH_SYP);
}
}
}
New watermark for pictures in C #