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

类别:.NET开发 点击:0 评论:0 推荐:
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(); 代码不难,不解决了

本文地址:http://com.8s8s.com/it/it41265.htm