这里讲得很明白:http://www.ondotnet.com/pub/a/dotnet/2002/04/01/asp.html?page=1

解决方案 »

  1.   

    <%@ Page Language="C#" Debug="true" %>
    <%@ import Namespace="System.IO" %>
    <%@ import Namespace="System.Drawing" %>
    <%@ import Namespace="System.Drawing.Imaging" %>
    <script runat="server">    void UploadBtn_Click(Object sender, EventArgs e)
             {
            /* string strpath=UploadFile.Value;
             int i=strpath.Length;
             while(i>0){
                char ch=strpath[i-1];
                if(ch=='\\' || ch=='/' || ch==':') break;
                i--;
                }
                string filename=strpath.Substring(i);
                Button1.Text=filename;
                return;  */
             UploadFile.PostedFile.SaveAs(Server.MapPath("test.jpg"));
             ImageEditor.Visible = true;
             }
        
             void UpdateBtn_Click(Object sender, EventArgs e)
        {
        
        
             System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath("test.jpg"));
             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("Lucida Sans Unicode", 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,IntPtr.Zero);
             image.Dispose();
             thumbImage.Save(Server.MapPath("test.jpg"), ImageFormat.Jpeg);
             }</script>
    <html>
    <head>
    </head>
    <body>
        <form enctype="multipart/form-data" runat="server">
            <h3>选择要上载的文件: 
                <input id="UploadFile" type="file" name="file2" runat="server" />
                <asp:button id="Button1" onclick="UploadBtn_Click" runat="server" text="Upload Me!"></asp:button>
                <hr />
                <asp:panel id="ImageEditor" runat="server" visible="false">
                    <img src="test.jpg" /> 
                    <h3>图象的宽度: 
                        <asp:textbox id="Width" runat="server"></asp:textbox>
                        图象的高度: 
                        <asp:textbox id="Height" runat="server"></asp:textbox>
                        <br />
                        文字的内容: 
                        <asp:textbox id="Caption" runat="server"></asp:textbox>
                        文字的大小: 
                        <asp:dropdownlist id="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>
                        <asp:button id="Button2" onclick="UpdateBtn_Click" runat="server" text="Update Image"></asp:button>
                    </h3>
                </asp:panel>
            </h3>
        </form>
    </body>
    </html>