代码我是网上看的,也没看出什么差错啊。
这个乱了,但是这张图却是正常的:
不清楚到底是什么原因,代码一样,只是图片不一样。
1 #region 设置文字的阴影 2 /// <summary> 3 /// 设置文字的阴影 4 /// </summary> 5 /// <param name="Pict"></param> 6 /// <param name="Str"></param> 7 /// <param name="font"></param> 8 /// <param name="pointf"></param> 9 /// <returns></returns> 10 private Image SetBadge(Image image, Font font, PointF pointf) 11 { 12 String str = Config.Text; 13 int imageWidth = image.Width; 14 int imageHeight = image.Height; 15 Color shadowColor = ColorTranslator.FromHtml(Config.ShadowColor); 16 Bitmap Var_bmp = new Bitmap(imageWidth,imageHeight); 17 Bitmap Var_SaveBmp = new Bitmap(image); 18 Graphics g = Graphics.FromImage(Var_bmp); 19 Graphics tem_Graphics = Graphics.FromImage(image); 20 g.Clear(Color.Transparent); 21 22 g.DrawString(str, font, new SolidBrush(shadowColor), pointf.X, pointf.Y); 23 int tem_Become = 100; 24 for (int x = 1; x < Var_bmp.Width; x++) 25 { 26 for (int y = 1; y < Var_bmp.Height; y++) 27 { 28 int tem_a, tem_r, tem_g, tem_b, tem_r1, tem_g1, tem_b1; 29 if (Var_bmp.GetPixel(x, y).ToArgb() == shadowColor.ToArgb() 30 || shadowColor == ColorTranslator.FromHtml(Config.FontColor)) 31 { 32 tem_a = Var_SaveBmp.GetPixel(x, y).A; 33 tem_r = Var_SaveBmp.GetPixel(x, y).R; 34 tem_g = Var_SaveBmp.GetPixel(x, y).G; 35 tem_b = Var_SaveBmp.GetPixel(x, y).B; 36 tem_r1 = tem_r; 37 tem_g1 = tem_g; 38 tem_b1 = tem_b; 39 40 if (tem_b + tem_Become < 255) 41 tem_b = tem_b + 255; 42 if (tem_g + tem_Become < 255) 43 tem_g = tem_g + 255; 44 if (tem_r + tem_Become < 255) 45 tem_r = tem_r + 255; 46 if (tem_r1 - tem_Become > 0) 47 tem_r1 = tem_r1 - tem_Become; 48 if (tem_g1 - tem_Become > 0) 49 tem_g1 = tem_g1 - tem_Become; 50 if (tem_b1 - tem_Become > 0) 51 tem_b1 = tem_b1 - tem_Become; 52 tem_Graphics.DrawEllipse(new Pen(new SolidBrush(shadowColor)), x + Config. OffsetU, y + Config.OffsetV, Config.ShadowSize, Config.ShadowSize);//绘制文字的阴影 53 tem_Graphics.DrawEllipse(new Pen(new SolidBrush(Color.FromArgb(tem_a, tem_r1, tem_g1, tem_b1))), x, y, 1, 1); 54 } 55 } 56 } 57 return image; 58 } 59 #endregion
用C#代码编辑器重新帖一边吧,看着蛋疼。
重新贴了,请指教!
tem_Graphics.DrawEllipse(new Pen(new SolidBrush(shadowColor)), x + Config.OffsetU, y + Config.OffsetV, Config.ShadowSize, Config.ShadowSize);//绘制文字的阴影 tem_Graphics.DrawEllipse(new Pen(new SolidBrush(Color.FromArgb(tem_a, tem_r1, tem_g1, tem_b1))), x, y, 1, 1);
@一碗豆浆:这两句有问题,你参数中的PointF和Config看是不是一致的,问题可能出在这儿。
两张图片分辨率和大小一样?
你仔细看看,貌似水印不是按像素大小来的,是按图片比例生成的吧.