CopyCode The Code is 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", 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)
{< br> 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)
{< br> lblerrinfo. TEXT = "no file selected";
}< br> else
{
string Path = server. mappath (". /uploads/"+ uploadfile. postedfile. filename. substring (uploadfile. postedfile. filename. lastindexof ('\') + 1);
If (file. exists (PATH)
{< br> lblerrinfo. TEXT = "a file with the same name already exists";
}< br> else
{< br> uploadfile. postedfile. saveas (PATH);
getthumbnailimage (width, height, straddinfo, left, right );
}< BR >}< br>
width: 100
Height: 150
</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>