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