上传时图片可以改大小,图上写字
2004-05-10 09:41
411 查看
%@ 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(Convert.ToInt32(Width.Text),Convert.ToInt32(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>
<%@ 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(Convert.ToInt32(Width.Text),Convert.ToInt32(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>
相关文章推荐
- jsp、js限制本地上传图片大小、类型(js经过测试,项目中可以使用)
- 如何在input标签选择图片上传并设置图片大小以及点击图片可以选择删除
- 图片转成BASE64字符串,然后以JSON的方式传递。当图片大小在1M左右的时候没问题,可以上传。但是当文件大小>1.5M的是否发现图片转BASE64不成功,居然得到的值是NULL
- 上传图片并可以调整图片大小
- 上传图片并且生成可以控制大小图片清晰度的方法
- 一个可以使得上传的图片大小按照指定的宽度,高度自动按比例进行缩放的函数(C#)
- 上传图片并且生成可以控制大小图片清晰度的方法
- ftp+nginx搭建图片服务器,上传FTP文件可以传到服务器上,但是文件大小是0字节的 而且点击按钮后程序会卡死
- 就是那个上传的。按实际上传时的文件名称保存(不在是test.jpg了)图片可以改大小,图
- 上传图片并且生成可以控制大小图片清晰度的方法
- js判断上传图片大小及尺寸
- js判断上传图片大小限制300k
- KindEditor 修改多图片上传显示限制大小和张数
- js实现判断图片上传判断大小
- 一般处理程序上传图片压缩图片大小
- ios上传图片到appstore时的尺寸大小
- PHP设置图片文件上传大小的方法
- 处理 input 上传图片,浏览器读取图片大小过程中遇到到的坑(兼容IE8\9)
- 限制ckeditor上传图片文件大小的方法
- java上传多张图片,并且可以删除上传的图片。