查看: 5354|回复: 0
打印 上一主题 下一主题

如何在上传的图片上打自己的文字水印

[复制链接]
跳转到指定楼层
1#
发表于 2008-9-11 21:02:12 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
台州网址导航
很多时候需要在用户上传的图片上加上版权或者一些其他的附加文字信息,如何实现这样的功能,下面帖个简单实现的例子,起到抛砖引玉的作用。

<%@PageLanguage="c#"Debug="true"Trace="true"%>
<%@ImportNamespace="System.IO"%>
<%@ImportNamespace="System.Drawing"%>
<%@ImportNamespace="System.Drawing.Imaging"%>
<html>
<scriptrunat=server>
voidUploadBtn_Click(Objectsender,EventArgse){
Stringfilename;
Stringfilename1;
String[]filename2;
intq;
filename=UploadFile.PostedFile.FileName;
filename2=filename.Split(newChar[]{'\\'});
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;
}
voidUpdateBtn_Click(Objectsender,EventArgse){
Stringfilename1;
filename1=Image1.Src;
System.Drawing.Imageimage=System.Drawing.Image.FromFile(Server.MapPath(filename1));
System.Drawing.Imagenewimage=newBitmap(image.Width,image.Height,PixelFormat.Format32bppRGB);
Graphicsg=Graphics.FromImage(newimage);
g.DrawImage(image,0,0,image.Width,image.Height);
Fontf=newFont(FontType.SelectedItem.Text,Int32.Parse(FontSize.SelectedItem.Text));
Brushb=newSolidBrush(Color.Red);
g.DrawString(Caption.Text,f,b,10,140);
g.Dispose();
System.Drawing.ImagethumbImage=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:labelid="dis"runat=server/>
<formenctype="multipart/form-data"runat=server>
选择上传文件:<inputid="UploadFile"type=filerunat=server>
<asp:buttonText="UploadMe!"OnClick="UploadBtn_Click"runat=server/>
<hr>
<asp:panelid="ImageEditor"Visible=falserunat=server>
<imgID="Image1"src=""runat="server"/>
图像宽度:<asp:textboxid="Width"runat=server/>
图像高度:<asp:textboxid="Height"runat=server/><br>
文本标题:<asp:textboxid="Caption"runat=server/>
标题字号:<asp:dropdownlistid="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:dropdownlistid="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:buttonText="UpdateImage"OnClick="UpdateBtn_Click"runat=server/>
</asp:panel>
</form>

</body>
</html>
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 转播转播 分享分享 分享淘帖
台州维博网络(www.tzweb.com)专门运用PHP+MYSQL/ASP.NET+MSSQL技术开发网站门户平台系统等。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

网站推广
关于我们
  • 台州朗动科技(Tzweb.com)拥有多年开发网站平台系统门户手机客户端等业务的成功经验。主要从事:政企网站,系统平台,微信公众号,各类小程序,手机APP客户端,浙里办微应用,浙政钉微应用、主机域名、虚拟空间、后期维护等服务,满足不同企业公司的需求,是台州地区领先的网络技术服务商!

Hi,扫描关注我

Copyright © 2005-2026 站长论坛 All rights reserved

Powered by 站长论坛 with TZWEB Update Techonolgy Support

快速回复 返回顶部 返回列表