<% @ 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", 14), 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 file selected ";
}
Else
{
String path = Server. mapPath (". /Uploads/"+ uploadFile. postedFile. fileName. substring (uploadFile. postedFile. fileName. lastIndexOf (''\'') + 1 ));
If (File. Exists (path ))
{
LblErrInfo. Text = "a file with the same name already exists ";
}
Else
{
UploadFile. PostedFile. SaveAs (path );
GetThumbnailImage (width, height, strAddInfo, left, right );
}
}
}
</Script>
<Html>
<Head>
</Head>
<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 information: <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 = "upload to generate a thumbnail" onServerClick = "Button_Click" runat = "server"/>
</P>
<P> <asp: Image id = "ImgPreview" runat = "server"> </asp: Image>
</P>
<! -- Insert content here -->
</Form>
</Body>
</Html>