按实际上传时的文件名称保存(不在是test.jpg了)图片可以改大小,图上写字(可选字体,我设的全是中文,^_^。大
小),没有解决字体颜色问题。
1@ Page Language="c#" Debug="true" Trace="true"
1@ Import Namespace="System.IO"
1@ Import Namespace="System.Drawing"
1@ Import Namespace="System.Drawing.Imaging"
1<html>
2<script runat="server">
3void UploadBtn_Click(Object sender, EventArgs e) {
4String filename;
5String filename1;
6String[] filename2;
7int q;
8filename=UploadFile.PostedFile.FileName ;
9filename2=filename.Split(new Char[] {'\\\'});
10q=filename2.GetUpperBound(0);
11filename1=filename2[q];
12dis.Text="上传文件名:"+filename1+"<br>";
13UploadFile.PostedFile.SaveAs(Server.MapPath(filename1));
14ImageEditor.Visible = true;
15dis.Text+="文件大小:"+UploadFile.PostedFile.ContentLength+"字节数";
16Image1.Src=filename1;
17}
18void UpdateBtn_Click(Object sender, EventArgs e) {
19String filename1;
20filename1=Image1.Src;
21System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(filename1));
22System.Drawing.Image newimage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppRGB);
23Graphics g = Graphics.FromImage(newimage);
24g.DrawImage(image,0,0,image.Width,image.Height);
25Font f = new Font(FontType.SelectedItem.Text, Int32.Parse(FontSize.SelectedItem.Text));
26Brush b = new SolidBrush(Color.Red);
27g.DrawString(Caption.Text, f, b, 10, 140);
28g.Dispose();
29System.Drawing.Image thumbImage = newimage.GetThumbnailImage(Int32.Parse(Width.Text),Int32.Parse
30(Height.Text),null,0);
31image.Dispose();
32thumbImage.Save(Server.MapPath(filename1), ImageFormat.JPEG);
33Image1.Src=filename1;
34Caption.Text="";
35
36}
37
38</script>
39<body>
40<asp:label id="dis" runat="server/">
41<form enctype="multipart/form-data" runat="server">
42<h3>
43
44Select File To Upload: <input id="UploadFile" runat="server" type="file"/>
45<asp:button onclick="UploadBtn_Click" runat="server/" text="Upload Me!">
46<hr/>
47<asp:panel id="ImageEditor" runat="server" visible="false">
48<img id="Image1" runat="server" src=""/>
49<h3>
50Image Width: <asp:textbox id="Width" runat="server/">
51
52Image Height: <asp:textbox id="Height" runat="server/"> <br/>
53
54Text Caption: <asp:textbox id="Caption" runat="server/">
55
56Caption Size: <asp:dropdownlist id="FontSize" runat="server">
57<asp:listitem>14</asp:listitem>
58<asp:listitem>18</asp:listitem>
59<asp:listitem>26</asp:listitem>
60<asp:listitem>36</asp:listitem>
61<asp:listitem>48</asp:listitem>
62<asp:listitem>62</asp:listitem>
63</asp:dropdownlist>
64Caption Font: <asp:dropdownlist id="FontType" runat="server">
65<asp:listitem>黑体</asp:listitem>
66<asp:listitem>仿宋</asp:listitem>
67<asp:listitem>隶书</asp:listitem>
68<asp:listitem>楷书</asp:listitem>
69<asp:listitem>方正姚体</asp:listitem>
70<asp:listitem>华文彩云</asp:listitem>
71</asp:dropdownlist>
72<asp:button onclick="UpdateBtn_Click" runat="server/" text="Update Image">
73</asp:button></asp:textbox></asp:textbox></asp:textbox></h3>
74</asp:panel>
75</asp:button></h3></form>
76</asp:label></body>
77</html>