Asp. NET to upload images and generate thumbnails with copyright information

Source: Internet
Author: User
The code is as follows:

<%@ page language= "C #" responseencoding= "gb2312"%> <%@ import namespace= "System"%> <%@ import namespace= "System.IO"%> <%@ Import namespace= "System.Drawing"%> <%@ import namespace= "System.Drawing.Imaging"%> <script runat= "Server" > 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", 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; s Tring 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 (path) {lblerrinfo.text= "already has a file with the same name";} else {uploadFile.PostedFile.SaveAs (path); file.exists; Getthumbnailimage (Width,height,straddinfo,left,right); }}} &LT;/SCRipt> 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.