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

ASP.NET
Check if a File is in Internet Explorers Cache
如何检测电脑是否安装了.net framework
[Regex]Greta不支持“Named Groups”特性
使用子類化的方法來實現VB對特殊消息的響應
C#软件启动设计
C#中虛函數,抽象,接口的簡單説明
TreeView的操作
InteliIM 3.0 will be released soon!
如何將 Visual Basic 與 ADO 搭配使用
建立永遠停留在最上層的窗口(VB)
C#中比较两个值型一维数组变量是否值相等
谈谈软件工程设计的艺术
批量添加Active Directory帐号
文件搜索的实现(深度搜索)
一个图形分割问题[答网友]
XML反串行化Namespace不统一而引起的错误
使用Javascript创建XML文件
突破MsComm控件RThreshold限制,全部数据统统收!
如何制作一个带启动屏幕的窗体
【翻译】Managed DirectX(第五章)

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 56 ::
收藏到网摘: 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(); 代码不难,不解决了