首页 新闻 会员 周边

C# 水印文字阴影,为何在不同图片上显示不一样?

0
悬赏园豆:5 [已解决问题] 解决于 2014-06-11 14:21

代码我是网上看的,也没看出什么差错啊。

 

这个乱了,但是这张图却是正常的:

 

不清楚到底是什么原因,代码一样,只是图片不一样。

 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
View Code

 

虔城墨客的主页 虔城墨客 | 初学一级 | 园豆:185
提问于:2013-05-17 13:51
< >
分享
最佳答案
0

用C#代码编辑器重新帖一边吧,看着蛋疼。

收获园豆:4
Eric.luo | 小虾三级 |园豆:853 | 2013-05-17 16:47

重新贴了,请指教!

虔城墨客 | 园豆:185 (初学一级) | 2013-05-17 18:02
                        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看是不是一致的,问题可能出在这儿。

Eric.luo | 园豆:853 (小虾三级) | 2013-05-17 18:45
其他回答(1)
0

两张图片分辨率和大小一样?

你仔细看看,貌似水印不是按像素大小来的,是按图片比例生成的吧.

收获园豆:1
flyher | 园豆:195 (初学一级) | 2013-05-17 15:35
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册