zoukankan      html  css  js  c++  java
  • 生成二维码

    //生成二维码
            private static Bitmap CreateQrCode(string printString)
            {
                EncodingOptions options = null;
                BarcodeWriter writer = null;
    
                options = new QrCodeEncodingOptions
                {
                    DisableECI = true,
                    CharacterSet = "UTF-8",
                    Width = 250,
                    Height =250
                };
                writer = new BarcodeWriter();
                writer.Format = BarcodeFormat.QR_CODE;
                writer.Options = options;
    
                Bitmap bitmap = writer.Write("0123456789");
                return bitmap;
    
            }
            /// <summary>
            /// 输出二维码
            /// </summary>
            /// <param name="exp">订单信息</param>
            /// <param name="picWidth">宽度</param>
            /// <param name="picHeight">高度</param>
            /// <param name="printString">二维码内容</param>
            /// <returns></returns>
            public static byte[] GetPrintPicture(Model.Pet_OrderO2O exp, int picWidth, int picHeight,string printString)
            {
                Bitmap image = CreateQrCode(printString);
                Bitmap printPicture = new Bitmap(picWidth, picHeight);
                
                Font font = new Font("黑体", 11f);
                Graphics g = Graphics.FromImage(printPicture);
                g.Clear(Color.White);
                Brush brush = new SolidBrush(Color.Black);
    
                g.SmoothingMode = SmoothingMode.HighQuality;
    
                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;//如果不填加反锯齿代码效果如图1
    
                int pointX = 5;
                Rectangle destRect = new Rectangle(190, 0, image.Width, image.Height);
                g.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
                int height = 40;
                RectangleF layoutRectangle = new RectangleF(pointX, height, 220f, 85f);
                g.DrawString("收货人 :" + exp.UserName, font, brush, layoutRectangle);
    
                //height += interval;
                //layoutRectangle = new RectangleF(pointX, height, 230f, 85f);
                //g.DrawString("省市区 :" + exp.Province+exp.City+exp.District, font, brush, layoutRectangle);
                height += 20;
                layoutRectangle = new RectangleF(pointX, height, 220f, 85f);
                g.DrawString("联系电话:" + exp.MobilePhone, font, brush, layoutRectangle);
    
                height += 20;
                layoutRectangle = new RectangleF(pointX, height, 220f, 85f);
                g.DrawString("收货地址:" + exp.ServiceAddr, font, brush, layoutRectangle);            
    
                height += 60;
                layoutRectangle = new RectangleF(pointX, height, 220f, 85f);
                g.DrawString("邮  编:" + exp.Postcode, font, brush, layoutRectangle);
    
                height += 20;
                layoutRectangle = new RectangleF(pointX, height, 220f, 85f);
                g.DrawString("备  注:" + exp.Remark, font, brush, layoutRectangle);
                MemoryStream stream = new MemoryStream();
                printPicture.Save(stream, ImageFormat.Jpeg);
                return stream.ToArray();
            }
  • 相关阅读:
    POJ -- 3468
    HDOJ--1698
    简单的API应用
    Linux引导流程
    Python 实现网络爬虫小程序
    codeforce
    Count the string -- HDOJ 3336
    初次运行 Git 前的配置
    leetcode244- Shortest Word Distance II- medium
    leetcode243- Shortest Word Distance- easy
  • 原文地址:https://www.cnblogs.com/Celebrator/p/4954127.html
Copyright © 2011-2022 走看看