[转]Asp.net上传图片并自动缩放图片大小
2007-10-19 01:20
435 查看
<%@ Import Namespace="System.Drawing.Imaging" %> <%@ Import Namespace="System.Drawing" %><%@ Import Namespace="System.IO" %><%@ Page Language="c#" Debug="true" Trace="true"%>
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+"
";
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,IntPtr.Zero);
image.Dispose();
thumbImage.Save(Server.MapPath(filename1), ImageFormat.Jpeg);
Image1.Src=filename1;
Caption.Text="";
}
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+"
";
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,IntPtr.Zero);
image.Dispose();
thumbImage.Save(Server.MapPath(filename1), ImageFormat.Jpeg);
Image1.Src=filename1;
Caption.Text="";
}
<%@ Import Namespace="System.Drawing.Imaging" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.IO" %>
<%@ Page Language="c#" Debug="true" Trace="true"%>
<HTML>
<script runat="server">
</script>
<body>
<asp:label id="dis" runat="server" />
<form enctype="multipart/form-data" runat="server" ID="Form1">
<h3>
Select File To Upload: <input id="UploadFile" type="file" runat="server" NAME="UploadFile">
<asp:button Text="Upload Me!" OnClick="UploadBtn_Click" runat="server" ID="Button1" />
<hr>
<asp:panel id="ImageEditor" Visible="false" runat="server">
<IMG id="Image1" src="" runat="server">
<H3>Image Width:
<asp:textbox id="Width" runat="server"></asp:textbox>Image Height:
<asp:textbox id="Height" runat="server"></asp:textbox><BR>
Text Caption:
<asp:textbox id="Caption" runat="server"></asp:textbox>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 id="Button2" onclick="UpdateBtn_Click" runat="server" Text="Update Image"></asp:Button></H3>
</asp:panel>
</form>
</H3>
<H3></H3>
</FORM>
</body>
</HTML>
相关文章推荐
- asp.net上传图片文件自动修改图片大小代码
- ASP.NET上传图片时改变图片的尺寸和文件大小
- ASP.NET FileUpload上传图片方法并解决上传文件大小
- Asp.net获取上传图片大小的尺寸!
- asp.net上传图片+自动生成缩略图+图片水印功能
- 网页上传图片 判断类型 检测大小 剪切图片 ASP.NET版本
- asp.net(C#)上传单个图片并判断图片的类型和大小
- asp.net 点缩略图弹出随图片大小自动调整的页面
- Asp.net实现同页面内多图片自动上传并带预览显示
- ASP.NET获取上传图片的大小
- asp.net 上传图片,自动压缩裁剪图片。
- 网页上传图片 判断类型 检测大小 剪切图片 ASP.NET版本
- ASP.NET学习笔记一:在上传图片的同时修改图片大小
- asp.net 获取上传图片的大小
- ASP.NET C# 按原图片大小缩放生成缩略图
- ASP.NET MVC中使用uploadify上传图片并按照规定大小压缩图片
- ASP.NET C# 按原图片大小等比例缩放生成缩略图
- ASP.NET上传图片,服务器端验证,宽度,高度,文件类型,尺寸,文件大小,图片上传,图片格式检查
- asp.net上传图片自动生成缩略图功能代码
- asp.net上传图片自动生成索引图片 (缩略图 index picture or thumbnail picture)