예제 #1
0
        /// <summary>
        /// 水印后依旧放剪贴板
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnFonts_Click(object sender, RoutedEventArgs e)
        {
            var model = WaterMarkImage();
            var img   = ClipboardHelper.GetOneImage();

            if (img == null)
            {
                MessageBox.Show("剪贴板没有图片信息");
            }
            else
            {
                ClipboardHelper.SetImage(WaterMarkHelper.SetWaterMark(img, model));
            }
        }
예제 #2
0
        /// <summary>
        /// 图片水印调用
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            //给水印对象赋对应的值
            WaterMark waterMark = new WaterMark();

            waterMark.WaterMarkType     = Enums.WaterMarkTypeEnum.Image;
            waterMark.ImgPath           = "水印.png";
            waterMark.WaterMarkLocation = Enums.WaterMarkLocationEnum.CenterCenter;
            waterMark.Transparency      = 0.7f;

            //调用
            Image successImage = WaterMarkHelper.SetWaterMark("text.png", waterMark);

            //保存
            successImage.Save("text2.png", System.Drawing.Imaging.ImageFormat.Png);

            MessageBox.Show("请查看软件根目录", "成功");
        }
예제 #3
0
        /// <summary>
        /// 文字水印调用
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //给水印对象赋对应的值
            WaterMark waterMark = new WaterMark();

            waterMark.WaterMarkType     = Enums.WaterMarkTypeEnum.Text;
            waterMark.Transparency      = 0.7f;
            waterMark.Text              = "dunitian.cnblogs.com";
            waterMark.FontStyle         = System.Drawing.FontStyle.Bold;
            waterMark.FontFamily        = "Consolas";
            waterMark.FontSize          = 20f;
            waterMark.BrushesColor      = System.Drawing.Brushes.YellowGreen;
            waterMark.WaterMarkLocation = Enums.WaterMarkLocationEnum.CenterCenter;

            //调用
            Image successImage = WaterMarkHelper.SetWaterMark("text.png", waterMark);

            //保存
            successImage.Save("text1.png", System.Drawing.Imaging.ImageFormat.Png);

            MessageBox.Show("请查看软件根目录", "成功");
        }
예제 #4
0
        /// <summary>
        /// 保存水印后的图片
        /// </summary>
        /// <param name="waterMark"></param>
        /// <param name="filePaths"></param>
        private static void SaveImages(WaterMark waterMark, string[] filePaths)
        {
            int num = 0;

            #region 存储专用
            //图片所处目录
            string dirPath = Path.GetDirectoryName(filePaths[0]);
            //存放目录
            string savePath = string.Format("{0}\\DNTWaterMark", dirPath);
            //是否存在,不存在就创建
            if (!Directory.Exists(savePath))
            {
                Directory.CreateDirectory(savePath);
            }
            #endregion
            foreach (string filePath in filePaths)
            {
                //文件名
                string fileName     = Path.GetFileName(filePath);
                var    successImage = WaterMarkHelper.SetWaterMark(filePath, waterMark);
                if (successImage != null)
                {
                    //保存图片
                    string imgPath = string.Format(@"{0}\{1}", savePath, fileName);
                    successImage.Save(imgPath, System.Drawing.Imaging.ImageFormat.Png);
                    num++;
                    DisposeImg(successImage);//1.1 释放资源
                }
            }
            //是否打开目录
            MessageBoxResult result = MessageBox.Show("逆天友情提醒:已转换 " + num + " 张图片~是否打开目录?", "转换状态~如果是原图,请检查下水印图片是否有问题", MessageBoxButton.YesNo);
            if (result == MessageBoxResult.Yes)
            {
                Process.Start("explorer.exe ", savePath);//打开保存后的路径
            }
        }