This article mainly introduces the method of generating thumbnail image and adding watermark to the original image, combined with specific examples to analyze the thumbnail image of the ASP and the implementation of the watermark operation, the need for friends can refer to the following
This paper introduces the method of generating thumbnail image and adding watermark to original graph. Share to everyone for your reference, as follows:
Using system.io;using system.drawing.imaging;private void Button1_serverclick (object sender, System.EventArgs e) { Graphics G=null; System.Drawing.Image Upimage=null; System.Drawing.Image Thumimg=null; System.Drawing.Image Simage=null; Bitmap Outputfile=null; try {string extension = Path.getextension (File1.PostedFile.FileName). ToUpper (); string filename = DateTime.Now.ToString ("Yyyymmddhhmmss"); String smallpath = Server.MapPath (".") + "/smallimg/"; String bigpath = Server.MapPath (".") + "/bigimg/"; int width,height,newwidth,newheight; System.Drawing.Image.GetThumbnailImageAbort callb =new System.Drawing.Image.GetThumbnailImageAbort ( Thumbnailcallback); if (! Directory.Exists (Smallpath)) directory.createdirectory (Smallpath); if (! Directory.Exists (Bigpath)) directory.createdirectory (Bigpath); Stream upimgfile = File1.PostedFile.InputStream; String simagefile = Server.MapPath ("a8logo.jpg"); The file to be watermarked simage=system.drawing.image.fromfile (simagefile); Upimage= System.Drawing.Image.FromStream (Upimgfile); The uploaded image width = upimage. Width; Height = upimage. Height; if (width>height) {newwidth=200; Newheight = (int) (double) height/(double) width * (double) newwidth); } else {newheight=200; newwidth= (int) (double) width/(double) height * (double) newheight); } thumimg = Upimage. Getthumbnailimage (Newwidth,newheight,callb,intptr.zero); Outputfile=new Bitmap (upimage); G=graphics.fromimage (outputfile); G.drawimage (simage,new Rectangle (upimage. Width-simage.width,upimage. Height-simage.height,upimage. Width,upimage. Height), 0,0,upimage. Width,upimage. Height,graphicsunit.pixel); String NewPath = bigpath + filename + extension; Original diagram path String thumpath = Smallpath + filename + extension; Thumbnail path outputfile. Save (NewPath); Thumimg. Save (Thumpath); OutputFile. Dispose (); } catch (Exception ex) {throw ex; } finally {if (g!=null) g.dispose (); if (thumimg!=null) ThumimG.dispose (); if (upimage!=null) upimage. Dispose (); if (simage!=null) simage. Dispose (); }}public bool Thumbnailcallback () {return false;}