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();
代碼不難,不解決了