程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> ASP編程 >> ASP技巧 >> asp+文件上傳增強實例

asp+文件上傳增強實例

編輯:ASP技巧

按實際上傳時的文件名稱保存(不在是test.jpg了)圖片可以改大小,圖上寫字(可選字體,我設的全是中文,^_^。大小),沒有解決字體顏色問題。

<%@ 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="Upload Me!" OnClick="UploadBtn_Click" runat=server/>

<hr>

<ASP:panel id="ImageEditor" Visible=false runat=server>

<img ID="Image1" src="" runat="server"/>

<h3>
Image Width: <ASP:textbox id="Width" runat=server/>

Image Height: <ASP:textbox id="Height" runat=server/> <br>

Text Caption: <ASP:textbox id="Caption" runat=server/>

Caption Size: <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>
Caption Font: <ASP:dropdownlist id="FontType" runat=server>
<asp:listitem>黑體</ASP:listitem>
<asp:listitem>仿宋</ASP:listitem>
<asp:listitem>隸書</ASP:listitem>
<asp:listitem>楷書</ASP:listitem>
<asp:listitem>方正姚體</ASP:listitem>
<asp:listitem>華文彩雲</ASP:listitem>
</ASP:dropdownlist>

<ASP:button Text="Update Image" OnClick="UpdateBtn_Click" runat=server/>

</h3>
</ASP:panel>

</form>

</body>
</Html>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved