• 生成二维码


    //生成二维码
            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();
            }
  • 相关阅读:
    rails采用MongoDB感觉相当不错!
    LWC: 将VF页面显示在LWC中
    Salesforce: System.TypeException: Invalid integer: 2185340704
    Salesforce: Report没有权限访问
    Maven Archetype 多 Module 自定义代码脚手架
    2021年度总结
    [转摘]Lucene学习总结之一:全文检索的基本原理
    DataTable.Rows.Remove(row) 与 DataTable.Rows[i].Delete()区别
    Lucene.net根据Sort走到了不同的类处理
    调用腾讯QQ天气预报的JS代码
  • 原文地址:https://www.cnblogs.com/Celebrator/p/4954127.html
Copyright © 2020-2023  润新知