Get the App
SLTechnology News&Howtos  ›  Development  › 

How ASP.NET uploads pictures and generates thumbnails with copyright information

Shulou Source: shulou.com Published: 2022-06-03 14:21:49 10月01日 Update

Editor to share with you how ASP.NET uploads pictures and generates thumbnails with copyright information, I believe most people do not know much about it, so share this article for your reference. I hope you will learn a lot after reading this article. Let's learn about it together.

The code is as follows:

Void Page_Load (Object sender, EventArgs e) {if (! Page.IsPostBack) {ImgPreview.Visible=false;}} void GetThumbnailImage (int width,int height,string strInfo,int left,int right) {string file= "Uploads/" + uploadFile.PostedFile.FileName.Substring (uploadFile.PostedFile.FileName.LastIndexOf ('\\) + 1); string newfile= "Uploads/" + uploadFile.PostedFile.FileName.Substring (uploadFile.PostedFile.FileName.LastIndexOf ('\') + 1) + ".jpg"; string strAdd=strInfo System.Drawing.Image oldimage = System.Drawing.Image.FromFile (Server.MapPath (file)); System.Drawing.Image thumbnailImage = oldimage.GetThumbnailImage (width, height,new System.Drawing.Image.GetThumbnailImageAbort (ThumbnailCallback), IntPtr.Zero); Response.Clear (); Bitmap output=new Bitmap (thumbnailImage); Graphics g=Graphics.FromImage (output); g.DrawString (strAdd,new Font ("Courier New", 14), new SolidBrush (Color.Red), left,right); output.Save (Server.MapPath (newfile), System.Drawing.Imaging.ImageFormat.Jpeg) Response.ContentType = "image/gif"; ImgPreview.Visible=true; ImgPreview.ImageUrl=newfile;} bool ThumbnailCallback () {return true;} void Button_Click (object sender, EventArgs e) {int width,height,left,right; string strAddInfo=txtAddInfo.Text; width=Int32.Parse (txtWidth.Text); height=Int32.Parse (txtHeight.Text); left=Int32.Parse (txtLeft.Text); right=Int32.Parse (txtRight.Text); if (! (uploadFile.PostedFile.ContentLength > 0)) {lblErrInfo.Text= "No file selected" } else {string path = Server.MapPath (". / Uploads/" + uploadFile.PostedFile.FileName.Substring (uploadFile.PostedFile.FileName.LastIndexOf ('\') + 1)); if (File.Exists (path)) {lblErrInfo.Text= "already has a file with the same name";} else {uploadFile.PostedFile.SaveAs (path); GetThumbnailImage (width,height,strAddInfo,left,right);}

Width:100 height:150

Add Information: AspxBoy.Com

Information location: left:10 right:135

The above is all the contents of the article "how ASP.NET uploads pictures and generates thumbnails with copyright information". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Information articles pictures copyright generation content files not much code location most more knowledge industry information information channels channels references learning help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Tech Info Shulou Information MariaDB Apple