WaterMarking

/// <summary>
        /// 给图片加上水印
        /// </summary>
        public void setWaterMarking()
        {

            // 建立一個 Bitmap   4:
            Bitmap OriginalImage = new Bitmap(tempPicture.Image);
            // 取得浮水印文字內容及其大小、显示位置 
            string sWaterMark = "1";
            int FontSize = ((OriginalImage.Width) / (sWaterMark.Length * 9));
            int x = OriginalImage.Width / 4;
            int y = OriginalImage.Height / 6;
            // 字体样式
            StringFormat DrawFormat = new StringFormat();
            DrawFormat.Alignment = StringAlignment.Center;
            DrawFormat.FormatFlags = StringFormatFlags.NoWrap;
            // 把字符串写到图片中 
            Graphics myGraphic = Graphics.FromImage(OriginalImage);
            myGraphic.DrawString("1", new Font("宋体", FontSize, FontStyle.Bold), new SolidBrush(Color.FromArgb(80, Color.Red)), x, y, DrawFormat);
            myGraphic.DrawString("2", new Font("宋体", FontSize, FontStyle.Bold), new SolidBrush(Color.FromArgb(80, Color.Red)), OriginalImage.Width - x, y, DrawFormat);
            myGraphic.DrawString("3", new Font("宋体", FontSize, FontStyle.Bold), new SolidBrush(Color.FromArgb(80, Color.Red)), x, OriginalImage.Height - y - FontSize, DrawFormat);
            myGraphic.DrawString("4", new Font("宋体", FontSize, FontStyle.Bold), new SolidBrush(Color.FromArgb(80, Color.Red)), OriginalImage.Width - x, OriginalImage.Height - y - FontSize, DrawFormat);
            // 把图片进行保存
            OriginalImage.Save("mytest.bmp");
            // 显示新图片
            mapBox.Load("mytest.bmp");
            if (myGraphic != null) myGraphic.Dispose();
        }

你可能感兴趣的:(water)