예제 #1
0
        /// <summary>
        /// 生成带Logo二维码
        /// </summary>
        /// <param name="content">内容</param>
        /// <param name="iconPath">logo路径</param>
        /// <param name="moduleSize">二维码的大小</param>
        /// <returns>输出流</returns>
        public static MemoryStream GetQRCode(string content, string iconPath, int moduleSize = 15)
        {
            QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.H);
            QrCode    qrCode    = qrEncoder.Encode(content);

            GraphicsRenderer render = new GraphicsRenderer(new FixedModuleSize(moduleSize, QuietZoneModules.Two), Brushes.Black, Brushes.White);

            DrawingSize dSize = render.SizeCalculator.GetSize(qrCode.Matrix.Width);
            Bitmap      map   = new Bitmap(dSize.CodeWidth, dSize.CodeWidth);
            Graphics    g     = Graphics.FromImage(map);

            render.Draw(g, qrCode.Matrix);

            //追加Logo图片 ,注意控制Logo图片大小和二维码大小的比例
            //PS:追加的图片过大超过二维码的容错率会导致信息丢失,无法被识别
            Image img = Image.FromFile(SysHelper.GetPath(iconPath));

            Point imgPoint = new Point((map.Width - img.Width) / 2, (map.Height - img.Height) / 2);

            g.DrawImage(img, imgPoint.X, imgPoint.Y, img.Width, img.Height);

            MemoryStream memoryStream = new MemoryStream();

            map.Save(memoryStream, ImageFormat.Jpeg);

            return(memoryStream);

            //生成图片的代码: map.Save(fileName, ImageFormat.Jpeg);//fileName为存放的图片路径
        }
예제 #2
0
        /// <summary>
        /// 创建根节点对象
        /// </summary>
        /// <param name="xmlFilePath">Xml文件的相对路径</param>
        private static XmlElement CreateRootElement(string xmlFilePath)
        {
            //定义变量,表示XML文件的绝对路径
            string filePath = "";

            //获取XML文件的绝对路径
            filePath = SysHelper.GetPath(xmlFilePath);

            //创建XmlDocument对象
            XmlDocument xmlDocument = new XmlDocument();

            //加载XML文件
            xmlDocument.Load(filePath);

            //返回根节点
            return(xmlDocument.DocumentElement);
        }
예제 #3
0
 /// <summary>
 /// 实例化XmlHelper对象
 /// </summary>
 /// <param name="xmlFilePath">Xml文件的相对路径</param>
 public XmlHelper(string xmlFilePath)
 {
     //获取XML文件的绝对路径
     _filePath = SysHelper.GetPath(xmlFilePath);
 }