)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » QrCode (Ia.Cl.Model)

Public general use code classes and xml files that we've compiled and used over the years:

QR Code support class.

    1: using System;
    2: using System.Drawing;
    3: using System.IO;
    4: using System.Windows.Media;
    5: using QRCoder;
    6:  
    7: namespace Ia.Cl.Model
    8: {
    9:     ////////////////////////////////////////////////////////////////////////////
   10:     /// <summary publish="true">
   11:     /// QR Code support class.
   12:     /// </summary>
   13:     /// <remarks> 
   14:     /// Copyright © 2016-2021 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   15:     ///
   16:     /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
   17:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   18:     ///
   19:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   20:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   21:     /// 
   22:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   23:     /// 
   24:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   25:     /// </remarks> 
   26:     public class QrCode
   27:     {
   28:         private readonly string text;
   29:         private readonly QRCodeGenerator qrCodeGenerator;
   30:         private readonly QRCodeData qrCodeData;
   31:         private readonly QRCode qrCode;
   32:         private readonly Bitmap bitmap;
   33:  
   34:         /*
   35:          * QR Code Data Capacity
   36:          * Numeric OnlyMax. 7089 characters
   37:          * AlphanumericMax. 4296 characters
   38:          * Binary (8 Bits) Max. 2953 characters
   39:         */
   40:  
   41:         private readonly int NumericOnlyDataMaxCapacity = 7089;
   42:         private readonly int AlphanumericDataMaxCapacity = 4296;
   43:         private readonly int BinaryDataMaxCapacity = 2953;
   44:  
   45:         ////////////////////////////////////////////////////////////////////////////
   46:  
   47:         /// <summary>
   48:         ///
   49:         /// </summary>
   50:         public QrCode(string text)
   51:         {
   52:             this.text = text.Substring(0, Math.Min(AlphanumericDataMaxCapacity, text.Length));
   53:  
   54:             qrCodeGenerator = new QRCodeGenerator();
   55:             qrCodeData = qrCodeGenerator.CreateQrCode(this.text, QRCodeGenerator.ECCLevel.Q);
   56:             qrCode = new QRCode(qrCodeData);
   57:             bitmap = qrCode.GetGraphic(20, System.Drawing.Color.Black, System.Drawing.Color.White, true);
   58:         }
   59:  
   60:         ////////////////////////////////////////////////////////////////////////////
   61:  
   62:         /// <summary>
   63:         ///
   64:         /// </summary>
   65:         public QrCode(string text, string foreColor, string backColor)
   66:         {
   67:             this.text = text.Substring(0, Math.Min(AlphanumericDataMaxCapacity, text.Length));
   68:  
   69:             qrCodeGenerator = new QRCodeGenerator();
   70:             qrCodeData = qrCodeGenerator.CreateQrCode(this.text, QRCodeGenerator.ECCLevel.Q);
   71:             qrCode = new QRCode(qrCodeData);
   72:             bitmap = qrCode.GetGraphic(20, System.Drawing.Color.FromName(foreColor), System.Drawing.Color.FromName(backColor), true);
   73:         }
   74:  
   75:         ////////////////////////////////////////////////////////////////////////////
   76:  
   77:         /// <summary>
   78:         ///
   79:         /// </summary>
   80:         public QrCode(string text, string foreColor, string backColor, string logoPath)
   81:         {
   82:             this.text = text.Substring(0, Math.Min(AlphanumericDataMaxCapacity, text.Length));
   83:  
   84:             qrCodeGenerator = new QRCodeGenerator();
   85:             qrCodeData = qrCodeGenerator.CreateQrCode(this.text, QRCodeGenerator.ECCLevel.Q);
   86:             qrCode = new QRCode(qrCodeData);
   87:             bitmap = qrCode.GetGraphic(20, System.Drawing.Color.FromName(foreColor), System.Drawing.Color.FromName(backColor), (Bitmap)Bitmap.FromFile(logoPath), 20, 1, true);
   88:         }
   89:  
   90:         ////////////////////////////////////////////////////////////////////////////
   91:  
   92:         /// <summary>
   93:         ///
   94:         /// </summary>
   95:         public string ImageUrlDataFormat
   96:         {
   97:             get
   98:             {
   99:                 return string.Empty; // Ia.Cl.Models.Image.ImageUrlDataFormat(bitmap);
  100:             }
  101:         }
  102:  
  103:         ////////////////////////////////////////////////////////////////////////////
  104:         ////////////////////////////////////////////////////////////////////////////
  105:     }
  106:  
  107:     ////////////////////////////////////////////////////////////////////////////
  108:     ////////////////////////////////////////////////////////////////////////////
  109: }