文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>WaterMarking

WaterMarking

时间:2010-08-24  来源:中大连长

/// <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();
        }

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载