热烈祝贺台州朗动科技的站长论坛隆重上线!(2012-05-28)    热烈庆祝伟大的祖国60周年生日 点击进来我们一起为她祝福吧(2009-09-26)    站长论坛禁止发布广告,一经发现立即删除。谢谢各位合作!.(2009-08-08)    热烈祝贺台州网址导航全面升级,全新版本上线!希望各位一如既往地支持台州网址导航的发展.(2009-03-28)    台州站长论坛恭祝各位新年快乐,牛年行大运!(2009-01-24)    台州Link正式更名为台州网址导航,专业做以台州网址为主的网址导航!(2008-05-23)    热烈祝贺台州Link资讯改名为中国站长资讯!希望在以后日子里得到大家的大力支持和帮助!(2008-04-10)    热烈祝贺台州Link论坛改名为台州站长论坛!希望大家继续支持和鼓励!(2008-04-10)    台州站长论坛原[社会琐碎]版块更名为[生活百科]版块!(2007-09-05)    特此通知:新台州站长论坛的数据信息全部升级成功!">特此通知:新台州站长论坛的数据信息全部升级成功!(2007-09-01)    台州站长论坛对未通过验证的会员进行合理的清除,请您谅解(2007-08-30)    台州网址导航|上网导航诚邀世界各地的网站友情链接和友谊联盟,共同引领网站导航、前进!(2007-08-30)    禁止发广告之类的帖,已发现立即删除!(2007-08-30)    希望各位上传与下载有用资源和最新信息(2007-08-30)    热烈祝贺台州站长论坛全面升级成功,全新上线!(2007-08-30)    
便民网址导航,轻松网上冲浪。
台州维博网络专业开发网站门户平台系统
您当前的位置: 首页 » ASP/ASP.NET编程 » 如何在上传的图片上打自己的文字水印

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

论坛链接
  • 如何在上传的图片上打自己的文字水印
  • 发布时间:2008-09-11 21:02:12    浏览数:5352    发布者:superadmin    设置字体【   
很多时候需要在用户上传的图片上加上版权或者一些其他的附加文字信息,如何实现这样的功能,下面帖个简单实现的例子,起到抛砖引玉的作用。

<%@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>
娱乐休闲专区A 影视预告B 音乐咖啡C 英语阶梯D 生活百科
网页编程专区E AMPZF HTMLG CSSH JSI ASPJ PHPK JSPL MySQLM AJAX
Linux技术区 N 系统管理O 服务器架设P 网络/硬件Q 编程序开发R 内核/嵌入
管理中心专区S 发布网址T 版主议事U 事务处理