用户登录  |  用户注册
首 页商业源码原创产品编程论坛
当前位置:PB创新网文章中心.Net

asp+文件上传增强实例

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2009-03-12 15:58:27
按实际上传时的文件名称保存(不在是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!" 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" runat=server/>

</h3>
</asp:panel>

</form>

</body>
</html>

Tags:

作者:佚名

文章评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论

栏目导航

本类热门阅览

相关文章

PB创新网ourmis.com】Copyright © 2000-2009 . All Rights Reserved .
页面执行时间:3,562.50000 毫秒
Email:ourmis@126.com QQ:2322888 蜀ICP备05006790号