IT猫扑网:您身边最放心的安全下载站! 最新更新| 软件分类| 专题汇总| 手机版

您当前所在位置:IT猫扑网 > 网络编程 > Asp编程 > 如何在上传的图片上打自己的文字水印

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

时间:2015-06-28 00:00 来源:IT猫扑网|http://www.itmop.com/ 作者:网管联盟 我要评论(0)

很多时候需要在用户上传的图片上加上版权或者一些其他的附加文字信息,如何实现这样的功能,下面帖个简单实现的例子,起到抛砖引玉的作用。


<%@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>

关键词标签:文字,自己,图片,上传

相关阅读 ASP编程代码:隐藏图片的真实地址 ASP教程:0177:800401f3错误解决 ASP代码中如何屏蔽ip地址 禁止某IP段访问网站 ASP彻底实现伪静态化html Ewebeditor及fckeditork单引号的问题 ASP实例:读取xml文件的程序

文章评论
发表评论

热门文章 Active Server Pages 错误 'ASP 0131'解决方法 Active Server Pages 错误 'ASP 0131'解决方法

相关下载

人气排行 ASP下标越界的解决方法 ASP代码中如何屏蔽ip地址 禁止某IP段访问网站 “文件共享锁定数溢出” 原因及解决方法 无法写入数据库的解决方法 ASP教程:0177:800401f3错误解决 ASP常用函数列表 如何用ASP来获取客户端真实IP的地址 ASP用FSO生成HTML简单实例+详解[原创] 用Asp编程实现QQ的在线情况查询 ASP彻底实现伪静态化html 解决:错误提示:Microsoft OLE DB Provider for ODBC Drivers (0x800040 如何在上传的图片上打自己的文字水印