当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 上传图片画带阴影的水印.(C#)

ASP.NET
GridView添加删除按钮终极办法
AjaxPro让.NET的AjaxPro变得简单
c# 实现Word联接Excel的MailMerge功能
解开Ajax技术中的达芬奇密码
专家讲解用.NET编写串口程序的一点心得
利用AJAX和ASP.NET实现简单聊天室
如何快速捕获.NET代码中隐藏的BUG
动态网页原理/.net面面观
从N层到.NET详细剖析原理(2)
从N层到.NET详细剖析原理(1)
ASP.NET效率陷阱之——Attributes
在ASP.NET 2.0中建立站点导航层次(5)
在ASP.NET 2.0中建立站点导航层次(4)
在ASP.NET 2.0中建立站点导航层次(3)
在ASP.NET 2.0中建立站点导航层次(2)
在ASP.NET 2.0中建立站点导航层次(1)
动态网站Web开发PHP、ASP还是ASP.NET(2)
动态网站Web开发PHP、ASP还是ASP.NET(1)
让Apache支持ASP.NET-Apache,ASP.NET
.Net下的数据备份和还原

ASP.NET 中的 上传图片画带阴影的水印.(C#)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 31 ::
收藏到网摘: n/a

ASP.NET上传图片后,要加上水印.比如网址. 文字为白色.但是当背景是白色的时候,水印根本看不到. 到处搜索资料,找画文字阴影的办法. 找了好几个,最后找了个老外的文章,和.Net自带文档里的说法一样. 居然是先画2-5个alpha值不同的灰色文字当阴影.. 再在上面,画正常颜色的文本....汗!!!!!!!!!!!!!!!!!!111 没有办法了,只好将就用了.效果还一般. Font font=new Font("Arial Black",15,FontStyle.Bold); SizeF sf=g.MeasureString("ImgGood.Com",font); PointF pf=new PointF(); pf.X=(250-sf.Width)/2; pf.Y=(bHeight-sf.Height)/2; //新建水印bmp Bitmap floatBmp=new Bitmap((int)sf.Width+3,(int)sf.Height+3,System.Drawing.Imaging.PixelFormat.Format32bppArgb); //Bitmap floatBmp=new Bitmap(250,100); //Bitmap floatBmp=new Bitmap((int)sf.Width,(int)sf.Height); Graphics fg=Graphics.FromImage(floatBmp); //画上阴影字符 PointF pt=new PointF(0,0); System.Drawing.Brush TransparentBrush0 = new System.Drawing.SolidBrush( System.Drawing.Color.FromArgb(50,System.Drawing.Color.Black ) ) ; System.Drawing.Brush TransparentBrush1 = new System.Drawing.SolidBrush( System.Drawing.Color.FromArgb(20,System.Drawing.Color.Black ) ) ; fg.DrawString("ImgGood.Com",font,TransparentBrush0,pt.X,pt.Y+1); fg.DrawString("ImgGood.Com",font,TransparentBrush0,pt.X+1,pt.Y); fg.DrawString("ImgGood.Com",font,TransparentBrush1,pt.X+1,pt.Y+1); fg.DrawString("ImgGood.Com",font,TransparentBrush1,pt.X,pt.Y+2); fg.DrawString("ImgGood.Com",font,TransparentBrush1,pt.X+2,pt.Y); TransparentBrush0.Dispose(); TransparentBrush1.Dispose(); //画上LOGO字符 fg.SmoothingMode=System.Drawing.Drawing2D.SmoothingMode.HighQuality; //fg.Clear(Color.Black); fg.DrawString("ImgGood.Com",font,new SolidBrush(Color.White),pt.X,pt.Y,StringFormat.GenericDefault); //画水印到 大图 fg.Save(); fg.Dispose(); //设置透明图像的颜色属性 float[][] ptsArray ={ new float[] {1, 0, 0, 0, 0}, new float[] {0, 1, 0, 0, 0}, new float[] {0, 0, 1, 0, 0}, new float[] {0, 0, 0, 0.5f, 0}, new float[] {0, 0, 0, 0, 1}}; ColorMatrix clrMatrix = new ColorMatrix(ptsArray); ImageAttributes imgAttributes = new ImageAttributes(); imgAttributes.SetColorMatrix(clrMatrix, ColorMatrixFlag.Default,ColorAdjustType.Bitmap); g.DrawImage(floatBmp,new Rectangle(10,10,(int)sf.Width,(int)sf.Height),0,0,(int)sf.Width,(int)sf.Height,GraphicsUnit.Pixel,imgAttributes); //======================================================================== g.Save(); g.Dispose(); bigBmp.Save(filePath + "B/" + fileName); bigBmp.Dispose(); 代码不难,不解决了