Copy Code code 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;
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 files 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 document of the same name";
}
Else
{
UploadFile.PostedFile.SaveAs (path);
Getthumbnailimage (Width,height,straddinfo,left,right);
}
}
}
</script>
<body>
<form method= "POST" enctype= "Multipart/form-data" runat= "Server" >
<p>
<input id= "UploadFile" type= "file" runat= "Server"/>
<asp:label id= "Lblerrinfo" runat= "Server" forecolor= "Red" ></asp:Label>
</p>
<p>
Width:<asp:textbox id= "TxtWidth" runat= "Server" width= "40px" >100</asp:TextBox>
Height:<asp:textbox id= "TxtHeight" runat= "Server" width= "40px" >150</asp:TextBox>
</p>
<p>
Add info: <asp:textbox id= "Txtaddinfo" runat= "Server" > Aspxboy.com</asp:textbox>
</p>
<p>
Information location: Left:<asp:textbox id= "Txtleft" runat= "Server" width= "40px" >10</asp:TextBox>
Right:<asp:textbox id= "Txtright" runat= "Server" width= "40px" >135</asp:TextBox>
</p>
<p>
<input id= "button" type= "button" value= "A sketch of the upload Build" onserverclick= "Button_Click" runat= "Server"/>
</p>
<p><asp:image id= "Imgpreview" runat= "Server" ></asp:Image>
</p>
<!--Insert content here-->
</form>
</body>