<summary>///Image Watermark (Image center)///</summary>//<param name= "Srcimgpath" > Original picture path </param>//<param name= "Waterpath" > Watermark image Path </param>//<param name= "waterwidth" > Watermark Area Width of the field </param>///<param Name= "waterheight" > Height of Watermark area </param>//<param name= "waterstring "> Watermark character </param>//<param name=" markposition "> Watermark location </param> public static void Makewat Erpic (String Srcimgpath, string waterpath, int waterwidth, int waterheight, string waterstring, String markposition = "in the picture ") {//1. Create an Image object using from the original image (Image img = image.fromfile (srcimgpath)) { 2. Initializes a new instance of the Bitmap class using (Bitmap map = new Bitmap (IMG) in the specified size and format. Width, IMG. Height, Pixelformat.format32bppargb)) {//3. Create a new Graphics object from the specified Image object using (Graphics g = graphics.fromimage (Map) {//4. Draws the original picture object at the specified position and at the specified size G.drawimage (IMG, new R Ectangle (0, 0, IMG. Width, IMG. Height), new RectangleF (0, 0, IMG. Width, IMG. Height), GraphicsUnit.Pixel); G.drawimage (Map2,new Rectangle (0, 0, map2. Width, Map2. Height)); Set the watermark font int fheight = img. HEIGHT/5; if (Fheight >) fheight = 16; Font drawfont = new Font ("Arial", fheight); Sets the watermark text position int disx = 0, Disy = 0; if (markposition = = "Picture middle") {DISX = (img. Width-waterwidth)/2; Disy = (img. Height-waterheight)/2; } StringFormat Drawformat = new StringFormat (); Drawformat.formatflags = Stringformatflags.nowrap; Text centered display drawformat.alignment = Stringalignment.center; Drawformat.linealignment = Stringalignment.center; SolidBrush Drawbrush = new SolidBrush (color.white); Fill Rectangle G.fillrectangle (drawbrush, New Rectangle (DISX, Disy, Waterwidth, waterheight)); Drawbrush.color = Color.Black; g.DrawString (waterstring, Drawfont, Drawbrush, New RectangleF (DISX, Disy, Waterwidth, waterheight), DrawFormat); Map. Save (Waterpath, imageformat.jpeg); } } } }
Two-dimensional Code business card