如何在上传的图片上写字
来源:互联网 发布:海外怎么淘宝 编辑:程序博客网 时间:2024/04/29 03:33
很多时候需要在用户上传的图片上加上版权或者一些其他的附加文字信息,如何实现这样的功能,下面帖个简单实现的例子,起到抛砖引玉的作用。
<%@ 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>
选择上传文件: <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"/>
图像宽度: <ASP:textbox id="Width" runat=server/>
图像高度: <ASP:textbox id="Height" runat=server/> <br>
文本标题: <ASP:textbox id="Caption" runat=server/>
标题字号: <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>
标题字体: <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/>
</ASP:panel>
</form>
</body>
</HTML>
- 如何在上传的图片上写字
- 如何在上传的图片上写字
- 如何在上传的图片上写字
- 一个实现图片上传/产生缩略图/在上传图片上写字功能的完整页面代码
- 在图片上写字
- 一个在图片上写字的方法
- hchxxzx--》一个实现图片上传/产生缩略图/在上传图片上写字功能的完整页面代码
- 如何在图片里写字
- winform中在图片上写字
- 在图片上写字 (C#)
- 利用php在图片上写字(中英文)
- 在一个图片上写字并保存
- matlab在图片上写字后保存
- 如何在图上写字,或者画画。
- 用canvas画的图片跟在图片上写字居中的问题?
- c#图片上写字
- 图片上写字
- Android画圆角矩形图片,并在图片上写字
- 模板:velocity和freemarker的比较
- 系统进程网络流量监控软件
- sql server 2000 日志文件丢失,附加数据库失败的解决办法
- 从MP3中提取歌曲信息(C#)
- DotNET(C#) Socket基本编程
- 如何在上传的图片上写字
- 实战Web服务
- 【责任分散效应】
- 为SAE写的一个mysql操作类
- 【帕金森定律】
- PHP编程学习之路 2
- 【晕轮效应】
- 制作tar.bz2格式文件命令
- 中点画直线算法