/// <summary> /// 文字水印 /// </summary> /// <param name="pic">原始图片</param> /// <param name="text">水印文字</param> /// <param name="place">水印位置</param> /// <param name="fontfamily">文字字体</param> /// <param name="fontsize">文字大小</param> /// <param name="fontcolor">文字颜色</param> public static void Mark(string pic, string text, MarkPlace place, string fontfamily, int?fontsize, Brush fontcolor) { using (Image txt = ToPicture(text, fontfamily, fontsize, fontcolor)) { Mark(pic, txt, place); } }
/// <summary> /// 图片水印 /// </summary> /// <param name="pic">原始图片</param> /// <param name="markImagePath">水印路径</param> /// <param name="place">水印位置</param> public static void Mark(string pic, string markImagePath, MarkPlace place) { using (var mark = Image.FromFile(markImagePath)) { Mark(pic, mark, place); } }
/// <summary> /// 水印 /// </summary> /// <param name="pic">原始图片</param> /// <param name="markImage">水印</param> /// <param name="place">水印位置</param> public static void Mark(string pic, Image markImage, MarkPlace place) { pic = Files.GetMapPath(pic); int y; var x = y = 0; using (var image = Image.FromFile(pic)) { switch (place) { case MarkPlace.RightBottom: x = image.Width - markImage.Width - 2; y = image.Height - markImage.Height - 2; break; case MarkPlace.LeftBottom: x = 12; y = image.Height - markImage.Height - 12; break; case MarkPlace.LeftTop: x = y = 12; break; case MarkPlace.RightTop: x = image.Width - markImage.Width - 12; y = 12; break; case MarkPlace.Center: x = (image.Width - markImage.Width) / 2; y = (image.Height - markImage.Height) / 2; break; } } Mark(pic, markImage, x, y); markImage.Dispose(); }
/// <summary> /// 文字水印 /// </summary> /// <param name="pic">原始图片</param> /// <param name="text">水印文字</param> /// <param name="place">水印位置</param> /// <param name="fontfamily">文字字体</param> /// <param name="fontsize">文字大小</param> /// <param name="fontcolor">文字颜色</param> public static void Mark(string pic, string text, MarkPlace place, string fontfamily, int? fontsize, Brush fontcolor) { using (Image txt = ToPicture(text, fontfamily, fontsize, fontcolor)) { Mark(pic, txt, place); } }
/// <summary> /// 水印 /// </summary> /// <param name="pic">原始图片</param> /// <param name="markImage">水印</param> /// <param name="place">水印位置</param> public static void Mark(string pic, Image markImage, MarkPlace place) { int y; var x = y = 0; using (var image = Image.FromFile(pic)) { switch (place) { case MarkPlace.RightBottom: x = image.Width - markImage.Width - 2; y = image.Height - markImage.Height - 2; break; case MarkPlace.LeftBottom: x = 12; y = image.Height - markImage.Height - 12; break; case MarkPlace.LeftTop: x = y = 12; break; case MarkPlace.RightTop: x = image.Width - markImage.Width - 12; y = 12; break; case MarkPlace.Center: x = (image.Width - markImage.Width) / 2; y = (image.Height - markImage.Height) / 2; break; } } Mark(pic, markImage, x, y); markImage.Dispose(); }