日期:2011-02-26  浏览次数:20423 次

<%@ Page Language="c#" Debug="true" Trace="true"%>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<html>
<script runat =server>
      void UploadBtn_Click(Object sender, EventArgs e) {
         String filename;
         String filename1;
         String[] filename2;
         int q;
         filename=UploadFile.PostedFile.FileName ;
         filename2=filename.Split(new Char[] {'\\'});
         q=filename2.GetUpperBound(0);
         filename1=filename2[q];
         dis.Text="上传文件名:"+filename1+"<br>";
         UploadFile.PostedFile.SaveAs(Server.MapPath(filename1));
         ImageEditor.Visible = true;
         dis.Text+="文件大小:"+UploadFile.PostedFile.ContentLength+"字节数";
         Image1.Src=filename1;      
      }
      void UpdateBtn_Click(Object sender, EventArgs e) {
         String filename1;
         filename1=Image1.Src;
         System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(filename1));
         System.Drawing.Image newimage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppRGB);
         Graphics g = Graphics.FromImage(newimage);
         g.DrawImage(image,0,0,image.Width,image.Height);
         Font f = new Font(FontType.SelectedItem.Text, Int32.Parse(FontSize.SelectedItem.Text));
         Brush b = new SolidBrush(Color.Red);
         g.DrawString(Caption.Text, f, b, 10, 140);
         g.Dispose();
         System.Drawing.Image thumbImage = 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:label id="dis" runat=server/>
     <form enctype="multipart/form-data" runat=server>

          <h3>

          Select File To Upload: <input id="UploadFile" type=file runat=server>

          <asp:button Text=