• 微信将用户信息转为一张图片(将html转为图片)


    注:效果如下图

    效果图1                                                                           效果图2

    原理1:将用户的个人信息写在图片上

    项目的解决方案如下请看标记的地方:

    代码展示如下:

    先引用  图片和文件处理类

    using System.Drawing;
    using System.IO;

    代码如下:

    Random rd = new Random();
    int a = rd.Next(1, 4);
    ///图片的路径 这里可以提供多张背景图随机选择
    string path = Server.MapPath(".") + "/img/" + a + ".png";
    //加文字水印,注意,这里的代码和以下加图片水印的代码不能共存
    System.Drawing.Image image = System.Drawing.Image.FromFile(path);

    Graphics g = Graphics.FromImage(image);

    g.DrawImage(image, 0, 0,640, 1080);
    Font f = new Font("Microsoft Yahei", 32);
    Brush b = new SolidBrush(Color.Black);
    string addText = "呢称";
    g.DrawString(addText, f, b, 230, 100);
    g.Dispose();

    //加图片水印 直接用之前的流不用再次读取
    // System.Drawing.Image image = System.Drawing.Image.FromFile(path);
    System.Drawing.Image copyImage = System.Drawing.Image.FromFile(Server.MapPath(".") + "/img/tx.jpg");
    Graphics g2 = Graphics.FromImage(image);
    g2.DrawImage(copyImage, new Rectangle(15, 15, 200, 200), 0, 0, copyImage.Width, copyImage.Height, GraphicsUnit.Pixel);
    g2.Dispose();


    //添加二维码快
    System.Drawing.Image copyImage2 = System.Drawing.Image.FromFile(Server.MapPath(".") + "/img/ewm.png");
    Graphics g3 = Graphics.FromImage(image);
    g3.DrawImage(copyImage2, new Rectangle(100, 560, 400, 400), 0, 0, copyImage2.Width, copyImage2.Height, GraphicsUnit.Pixel);
    g3.Dispose();
    //添加失效日期
    Graphics g4 = Graphics.FromImage(image);
    g4.DrawImage(image, 0, 0, 640, 1080);
    Font f1 = new Font("Microsoft Yahei", 16);
    Brush b1 = new SolidBrush(Color.Black);
    string addText2 = "于" + DateTime.Now.AddDays(7).ToString("yyyy-MM-dd") + "失效";
    g4.DrawString(addText2, f1, b1, 200, 1000);
    g4.Dispose();


    //保存加水印过后的图片
    string newPath = Server.MapPath(".") + "/img/bg2.jpg";
    image.Save(newPath);
    image.Dispose();

  • 相关阅读:
    网站SEO优化问答精选
    用eclipse怎样将本地的项目打成jar包上传到maven仓库
    查询linux机器的公网ip
    Srping mvc mabatis 报错 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
    使用SecureCRT的SFTP在WINDOWS与LINUX之间传输文件(转载)
    苹果手机如何减少后台流量
    《图解CSS3——第4章 CSS3背景-2》
    《图解CSS3——第4章 CSS3背景-1》
    《图解CSS3——第3章 CSS3边框-4》
    《图解CSS3——第3章 CSS3边框-3》
  • 原文地址:https://www.cnblogs.com/lookweb/p/5777562.html
Copyright © 2020-2023  润新知