zoukankan      html  css  js  c++  java
  • 给图片添加文字水印

    public void ImageWaterMarkText(string filename, ImageFormat format)
            {
                Image originalImage = Image.FromFile(filename);
                Graphics g = Graphics.FromImage(originalImage);
                
                Font drawFont = new Font("Arial", 12, FontStyle.Regular, GraphicsUnit.Pixel);
               //找到图片旋转中点
    float xpos = originalImage.Width > originalImage.Height ? originalImage.Width - originalImage.Height/ 2 : originalImage.Width / 2; float ypos = originalImage.Width > originalImage.Height ? originalImage.Height / 2 : originalImage.Height - originalImage.Width / 2; var triggleLeg = (originalImage.Width > originalImage.Height ? originalImage.Height : originalImage.Width) / 3; ar gPath = new GraphicsPath(); gPath.AddLine(originalImage.Width - triggleLeg, originalImage.Height, originalImage.Width, originalImage.Height - triggleLeg); gPath.AddLine(originalImage.Width, originalImage.Height - triggleLeg, originalImage.Width, originalImage.Height); gPath.AddLine(originalImage.Width, originalImage.Height, originalImage.Width - triggleLeg, originalImage.Height); g.FillPath(new SolidBrush(Color.FromArgb(120, Color.Black)), gPath);              g.TranslateTransform(xpos, ypos); g.RotateTransform(-45); SizeF crSize; string watermarkText;
    watermarkText
    = "测试文字"; crSize = g.MeasureString("Chine LianTong", drawFont); g.DrawString(watermarkText, drawFont, new SolidBrush(Color.Red), -crSize.Width / 2, 250); watermarkText = DateTime.Now.ToString("Current: yyyy-MM-dd HH:mm"); g.DrawString(watermarkText, drawFont, new SolidBrush(Color.Red), -crSize.Width / 2, 250 + crSize.Height + 5); g.Dispose(); MemoryStream stream = new MemoryStream(); originalImage.Save(stream, format); originalImage.Dispose(); Image img = Image.FromStream(stream); img.Save(filename); img.Dispose(); }
  • 相关阅读:
    AtCoDeer and Election Report
    乒乓球
    dp(装箱)
    《非你莫属》面试者现场跟面试官用英文对话,一口流利的英语口语厉害了
    冬天喝酸奶,可以加热吗?冬天喝酸奶,这4个方面要注意
    滑县两个富豪打赌,一人吃了一泡狗屎
    为什么外国富豪都喜欢捐光所有财产
    发的微博有敏感词
    社交网络
    怎么把word中的文字拉细变瘦长
  • 原文地址:https://www.cnblogs.com/sgciviolence/p/6432970.html
Copyright © 2011-2022 走看看