Many times need to upload a picture of the user to add copyright or some other additional text information, how to achieve such a function, below a simple implementation of the example, play a role.
<% @PageLanguage = "C #" debug= "true" trace= "true"%>
<% @ImportNamespace = "System.IO"%>
<% @ImportNamespace = "System.Drawing"%>
<% @ImportNamespace = "System.Drawing.Imaging"%>
<scriptrunat=server>
Voiduploadbtn_click (OBJECTSENDER,EVENTARGSE) {
Stringfilename;
Stringfilename1;
string[]filename2;
INTQ;
Filename=uploadfile.postedfile.filename;
Filename2=filename. Split (newchar[]{'});
Q=filename2. GetUpperBound (0);
FILENAME1=FILENAME2[Q];
Dis. text= "Upload filename:" +filename1+ "<br>";
UploadFile.PostedFile.SaveAs (Server.MapPath (filename1));
Imageeditor.visible=true;
Dis. text+= "File size:" +uploadfile.postedfile.contentlength+ "number of bytes";
image1.src=filename1;
}
Voidupdatebtn_click (OBJECTSENDER,EVENTARGSE) {
Stringfilename1;
FILENAME1=IMAGE1.SRC;
System.drawing.imageimage=system.drawing.image.fromfile (Server.MapPath (filename1));
System.drawing.imagenewimage=newbitmap (image. Width,image. HEIGHT,PIXELFORMAT.FORMAT32BPPRGB);
Graphicsg=graphics.fromimage (NewImage);
G.drawimage (image,0,0,image. Width,image. Height);
Fontf=newfont (Fonttype.selecteditem.text,int32.parse (FontSize.SelectedItem.Text));
Brushb=newsolidbrush (color.red);
g.DrawString (caption.text,f,b,10,140);
G.dispose ();
System.drawing.imagethumbimage=newimage. Getthumbnailimage (Int32.Parse (width.text), Int32.Parse
(Height.text), null,0);
Image. Dispose ();
Thumbimage.save (Server.MapPath (filename1), imageformat.jpeg);
image1.src=filename1;
Caption.text= "";
}
</script>
<body>
<asp:labelid= "Dis" runat=server/>
<formenctype= "Multipart/form-data" runat=server>
Select Upload file: <inputid= "UploadFile" type=filerunat=server>
<asp:buttontext= "uploadme!" onclick= "Uploadbtn_click" runat=server/>
<asp:panelid= "Imageeditor" visible=falserunat=server>
Image width: <asp:textboxid= "width" runat=server/>
Image height: <asp:textboxid= "height" runat=server/><br>
Text title: <asp:textboxid= "Caption" runat=server/>
Title Font size: <asp:dropdownlistid= "FontSize" runat=server>
<asp:listitem>14</asp:listitem>
<asp:listitem>18</asp:listitem>
<asp:listitem>26</asp:listitem>
<asp:listitem>36</asp:listitem>
<asp:listitem>48</asp:listitem>
<asp:listitem>62</asp:listitem>
</asp:dropdownlist>
Title font: <asp:dropdownlistid= "Fonttype" runat=server>
<asp:listitem> Bold </asp:listitem>
<asp:listitem> Imitation </asp:listitem>
<asp:listitem> Official Script </asp:listitem>
<asp:listitem> Regular Script </asp:listitem>
<asp:listitem> Choi Wan </asp:listitem>
<asp:listitem> New Wei </asp:listitem>
</asp:dropdownlist>
<asp:buttontext= "UpdateImage" onclick= "Updatebtn_click" runat=server/>
</asp:panel>
</form>
</body>