Web Upload image plus watermark

Source: Internet
Author: User

Uploading images and watermarks you need to use the control FileUpload upload button Image control to display uploaded pictures, page dragged into three controls

1<form id="Form1"runat="Server">2<asp:fileupload id="FileUpload1"runat="Server"accept=". Jpg,.jpeg,.png"/>3<asp:button id="Button1"runat="Server"text="Upload"/>4<asp:image id="Image1"runat="Server"/>5</form>

JS End limit does not choose to upload pictures upload pictures too large

1<script>2document.getElementById ("Button1"). onclick =function () {3         varf = document.getElementById ("FileUpload1");4         if(F.value.length <=0)//No files selected for upload5         {6Alert"Please select the uploaded file! ");7             return false;8         }9         if(f.files[0].size > (1024x768*1024x768*Ten))//limit the size of the uploaded file to 10MBTen         { OneAlert"file too large, not allowed to upload! "); A             return false; -         } -     }; the</script>

Select Image click upload Add watermark upload display descendant code on the interface

1 usingSystem.Drawing;//Painting Reference System.Drawing namespaces2 3 protected voidPage_Load (Objectsender, EventArgs e)4     {5Button1.click+=button1_click;//Upload button6     }7 8     voidButton1_Click (Objectsender, EventArgs e)9     {Ten         //2. Create a System.Drawing.Image object and use the FromStream method to System.IO the object OneSystem.Drawing.Image img =System.Drawing.Image.FromStream (fileupload1.filecontent); A        //1. Painting with graphics This class, using the FromImage method to point to the canvas, requires System.Drawing.Image object -Graphics g =graphics.fromimage (IMG); -        //4 Create S-draw content F-font B-Paint brush the        strings ="www.baidu.com"; -Font f =NewFont ("blackbody", the); -Brush B =NewSolidBrush (color.red); -        //3. Draw DrawString method S-drawn content F-font B-brush from where to start drawing +g.DrawString (S, F, B, Max, the ); -        //5 save img. Save to make a saved path +        stringPath ="images/"+ DateTime.Now.ToString ("yyyymmddhhssmm") +Fileupload1.filename; A img. Save (Server.MapPath (path)); at         //page Show Pictures -Image1.imageurl =path;  -}

The page appears as follows:

Web Upload image plus watermark

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.