Esempio n. 1
0
 private Bitmap GenerateQRCode(string URL, System.Drawing.Color DarkColor, System.Drawing.Color LightColor)
 {
     Form1.ActiveForm.Text = URL;
     var Encoder= new Gma.QrCodeNet.Encoding.QrEncoder(Gma.QrCodeNet.Encoding.ErrorCorrectionLevel.L);
     var Code = Encoder.Encode(URL);
     double hd = getDiff(256, Code.Matrix.Height);
     double wd = getDiff(256, Code.Matrix.Width);
     double fd = Math.Floor(Math.Min(hd, wd));
     int ifd = int.Parse(fd.ToString());
     var TempBMP = new Bitmap(256, 256);
     Graphics g = Graphics.FromImage(TempBMP);
     
     for (int X = 0; X < Code.Matrix.Width; X++)
     {
         for (int Y = 0; Y < Code.Matrix.Height;Y++ )
         {
             if (Code.Matrix.InternalArray[X, Y])
             {
                 g.FillRectangle(new SolidBrush(DarkColor), X * ifd.ToFloat(), Y * ifd.ToFloat(), ifd.ToFloat(), ifd.ToFloat());
             }
             else
             {
                 g.FillRectangle(new SolidBrush(LightColor), X * ifd.ToFloat(), Y * ifd.ToFloat(), ifd.ToFloat(), ifd.ToFloat());
             }
         }
     }
     
     return TempBMP;
 }
Esempio n. 2
0
        private Bitmap GenerateQRCode(string URL, System.Drawing.Color DarkColor, System.Drawing.Color LightColor)
        {
            Form1.ActiveForm.Text = URL;
            var      Encoder = new Gma.QrCodeNet.Encoding.QrEncoder(Gma.QrCodeNet.Encoding.ErrorCorrectionLevel.L);
            var      Code    = Encoder.Encode(URL);
            double   hd      = getDiff(256, Code.Matrix.Height);
            double   wd      = getDiff(256, Code.Matrix.Width);
            double   fd      = Math.Floor(Math.Min(hd, wd));
            int      ifd     = int.Parse(fd.ToString());
            var      TempBMP = new Bitmap(256, 256);
            Graphics g       = Graphics.FromImage(TempBMP);

            for (int X = 0; X < Code.Matrix.Width; X++)
            {
                for (int Y = 0; Y < Code.Matrix.Height; Y++)
                {
                    if (Code.Matrix.InternalArray[X, Y])
                    {
                        g.FillRectangle(new SolidBrush(DarkColor), X * ifd.ToFloat(), Y * ifd.ToFloat(), ifd.ToFloat(), ifd.ToFloat());
                    }
                    else
                    {
                        g.FillRectangle(new SolidBrush(LightColor), X * ifd.ToFloat(), Y * ifd.ToFloat(), ifd.ToFloat(), ifd.ToFloat());
                    }
                }
            }

            return(TempBMP);
        }
Esempio n. 3
0
        /*
         * public static string GerarQRCode(CamadaDados.Faturamento.PDV.TRegistro_NFCe rNFCe)
         * {
         *  if (rNFCe.St_contingencia)
         *  {
         *      System.Collections.Hashtable hs = new System.Collections.Hashtable();
         *      rNFCe.Chave_acesso = NFCe.GerarXML.TGerarXML.MontarChaveAcessoNfe(rNFCe, true).Trim();
         *      hs.Add("@P_CHAVE", rNFCe.Chave_acesso);
         *      hs.Add("@P_EMPRESA", rNFCe.Cd_empresa);
         *      hs.Add("@P_ID_NFCE", rNFCe.Id_nfcestr);
         *      new CamadaDados.TDataQuery().executarSql("update tb_pdv_nfce set chave_acesso = @P_CHAVE, dt_alt = getdate() " +
         *                                                "where cd_empresa = @P_EMPRESA and id_nfce = @P_ID_NFCE", hs);
         *  }
         *  string dest = string.Empty;
         *  if(rNFCe.rCliente == null ? false : !string.IsNullOrEmpty((rNFCe.rCliente.Nr_cgc + rNFCe.rCliente.Nr_cpf).SoNumero()))
         *  {
         *      if (rNFCe.rCliente.Tp_pessoa.Trim().ToUpper().Equals("F") && !string.IsNullOrEmpty(rNFCe.rCliente.Nr_cpf.SoNumero()))
         *          dest = rNFCe.rCliente.Nr_cpf.SoNumero();
         *      else if (rNFCe.rCliente.Tp_pessoa.Trim().ToUpper().Equals("J") && !string.IsNullOrEmpty(rNFCe.rCliente.Nr_cgc.SoNumero()))
         *          dest = rNFCe.rCliente.Nr_cgc.SoNumero();
         *  }
         *  else if (!string.IsNullOrEmpty(rNFCe.Nr_cgc_cpf.SoNumero()) &&
         *           (rNFCe.Nr_cgc_cpf.SoNumero().Length.Equals(14) ||
         *            rNFCe.Nr_cgc_cpf.SoNumero().Length.Equals(11)))
         *      dest = rNFCe.Nr_cgc_cpf.SoNumero();
         *  string str = "chNFe=" + GerarXML.TGerarXML.MontarChaveAcessoNfe(rNFCe, true).Trim() + "&" +
         *                "nVersao=100&" +
         *                "tpAmb=" + rNFCe.rCfgNFCe.Tp_ambiente_nfce.Trim() + "&" +
         *                (string.IsNullOrEmpty(dest) ? string.Empty : "cDest=" + dest.Trim() + "&") +
         *                "dhEmi=" + rNFCe.Dt_emissao.Value.ToString("yyyy-MM-ddTHH:mm:sszzz").ConvertHexaDecimal().ToLower() + "&" +
         *                "vNF=" + Convert.ToDecimal(string.Format("{0:N2}", rNFCe.Vl_cupom)).ToString(new System.Globalization.CultureInfo("en-US", true)) + "&" +
         *                "vICMS=" + Convert.ToDecimal(string.Format("{0:N2}", rNFCe.lItem.Sum(v => v.Vl_icms))).ToString(new System.Globalization.CultureInfo("en-US", true)) + "&" +
         *                "digVal=" + rNFCe.Digval.ConvertHexaDecimal().ToLower() + "&" +
         *                "cIdToken=" + rNFCe.rCfgNFCe.Id_tokencsc.Trim() + rNFCe.rCfgNFCe.Nr_csc.Trim();
         *  string strQRCode = rNFCe.rCfgNFCe.Url_nfce.Trim() +
         *                     "chNFe=" + GerarXML.TGerarXML.MontarChaveAcessoNfe(rNFCe, true).Trim() + "&" +
         *                     "nVersao=100&" +
         *                     "tpAmb=" + rNFCe.rCfgNFCe.Tp_ambiente_nfce.Trim() + "&" +
         *                     (string.IsNullOrEmpty(dest) ? string.Empty : "cDest=" + dest.Trim() + "&") +
         *                     "dhEmi=" + rNFCe.Dt_emissao.Value.ToString("yyyy-MM-ddTHH:mm:sszzz").ConvertHexaDecimal().ToLower() + "&" +
         *                     "vNF=" + Convert.ToDecimal(string.Format("{0:N2}", rNFCe.Vl_cupom)).ToString(new System.Globalization.CultureInfo("en-US", true)) + "&" +
         *                     "vICMS=" + Convert.ToDecimal(string.Format("{0:N2}", rNFCe.lItem.Sum(v => v.Vl_icms))).ToString(new System.Globalization.CultureInfo("en-US", true)) + "&" +
         *                     "digVal=" + rNFCe.Digval.ConvertHexaDecimal().ToLower() + "&" +
         *                     "cIdToken=" + rNFCe.rCfgNFCe.Id_tokencsc.Trim() + "&" +
         *                     "cHashQRCode=" + Utils.Estruturas.SHA1(str).ToLower().Trim();
         *  //Gerar Imagem QR Code
         *  Gma.QrCodeNet.Encoding.QrCode code = new Gma.QrCodeNet.Encoding.QrCode();
         *  Gma.QrCodeNet.Encoding.QrEncoder encoder = new Gma.QrCodeNet.Encoding.QrEncoder(Gma.QrCodeNet.Encoding.ErrorCorrectionLevel.M);
         *  code = encoder.Encode(strQRCode);
         *  Gma.QrCodeNet.Encoding.Windows.Render.GraphicsRenderer gRender =
         *      new Gma.QrCodeNet.Encoding.Windows.Render.GraphicsRenderer(new Gma.QrCodeNet.Encoding.Windows.Render.FixedModuleSize(4, Gma.QrCodeNet.Encoding.Windows.Render.QuietZoneModules.Zero),
         *                                                                 System.Drawing.Brushes.Black, System.Drawing.Brushes.White);
         *  System.IO.MemoryStream ms = new System.IO.MemoryStream();
         *  gRender.WriteToStream(code.Matrix, System.Drawing.Imaging.ImageFormat.Jpeg, ms);
         *  rNFCe.QR_Code = System.Drawing.Image.FromStream(ms);
         *  return strQRCode;
         * }
         */
        public static string GerarQRCode2(CamadaDados.Faturamento.PDV.TRegistro_NFCe rNFCe)
        {
            string strQRCode = string.Empty;

            if (rNFCe.St_contingencia)
            {
                System.Collections.Hashtable hs = new System.Collections.Hashtable();
                rNFCe.Chave_acesso = NFCe.GerarXML.TGerarXML.MontarChaveAcessoNfe(rNFCe, true).Trim();
                hs.Add("@P_CHAVE", rNFCe.Chave_acesso);
                hs.Add("@P_EMPRESA", rNFCe.Cd_empresa);
                hs.Add("@P_ID_NFCE", rNFCe.Id_nfcestr);
                new CamadaDados.TDataQuery().executarSql("update tb_pdv_nfce set chave_acesso = @P_CHAVE, dt_alt = getdate() " +
                                                         "where cd_empresa = @P_EMPRESA and id_nfce = @P_ID_NFCE", hs);
                string str = GerarXML.TGerarXML.MontarChaveAcessoNfe(rNFCe, true).Trim() + "|" +
                             "2|" +
                             rNFCe.rCfgNFCe.Tp_ambiente_nfce.Trim() + "|" +
                             rNFCe.Dt_emissao.Value.ToString("dd/MM/yyyy").Substring(0, 2) + "|" +
                             Convert.ToDecimal(string.Format("{0:N2}", rNFCe.Vl_cupom)).ToString(new System.Globalization.CultureInfo("en-US", true)) + "|" +
                             rNFCe.Digval.ConvertHexaDecimal() + "|" +
                             int.Parse(rNFCe.rCfgNFCe.Id_tokencsc) + rNFCe.rCfgNFCe.Nr_csc.Trim();
                strQRCode = rNFCe.rCfgNFCe.Url_nfce.Trim() + "?p=" +
                            GerarXML.TGerarXML.MontarChaveAcessoNfe(rNFCe, true).Trim() + "|" +
                            "2|" +
                            rNFCe.rCfgNFCe.Tp_ambiente_nfce.Trim() + "|" +
                            rNFCe.Dt_emissao.Value.ToString("dd/MM/yyyy").Substring(0, 2) + "|" +
                            Convert.ToDecimal(string.Format("{0:N2}", rNFCe.Vl_cupom)).ToString(new System.Globalization.CultureInfo("en-US", true)) + "|" +
                            rNFCe.Digval.ConvertHexaDecimal() + "|" +
                            int.Parse(rNFCe.rCfgNFCe.Id_tokencsc) + "|" +
                            Estruturas.SHA1(str).Trim();
            }
            else
            {
                string str = GerarXML.TGerarXML.MontarChaveAcessoNfe(rNFCe, true).Trim() + "|" +
                             "2|" +
                             rNFCe.rCfgNFCe.Tp_ambiente_nfce.Trim() + "|" +
                             int.Parse(rNFCe.rCfgNFCe.Id_tokencsc) + rNFCe.rCfgNFCe.Nr_csc.Trim();
                strQRCode = rNFCe.rCfgNFCe.Url_nfce.Trim() + "?p=" +
                            GerarXML.TGerarXML.MontarChaveAcessoNfe(rNFCe, true).Trim() + "|" +
                            "2|" + //Versão do QRCode
                            rNFCe.rCfgNFCe.Tp_ambiente_nfce.Trim() + "|" +
                            int.Parse(rNFCe.rCfgNFCe.Id_tokencsc) + "|" +
                            Estruturas.SHA1(str).Trim();
            }
            //Gerar Imagem QR Code
            Gma.QrCodeNet.Encoding.QrCode    code    = new Gma.QrCodeNet.Encoding.QrCode();
            Gma.QrCodeNet.Encoding.QrEncoder encoder = new Gma.QrCodeNet.Encoding.QrEncoder(Gma.QrCodeNet.Encoding.ErrorCorrectionLevel.M);
            code = encoder.Encode(strQRCode);
            Gma.QrCodeNet.Encoding.Windows.Render.GraphicsRenderer gRender =
                new Gma.QrCodeNet.Encoding.Windows.Render.GraphicsRenderer(new Gma.QrCodeNet.Encoding.Windows.Render.FixedModuleSize(4, Gma.QrCodeNet.Encoding.Windows.Render.QuietZoneModules.Zero),
                                                                           System.Drawing.Brushes.Black, System.Drawing.Brushes.White);
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            gRender.WriteToStream(code.Matrix, System.Drawing.Imaging.ImageFormat.Jpeg, ms);
            rNFCe.QR_Code = System.Drawing.Image.FromStream(ms);
            return(strQRCode);
        }
Esempio n. 4
0
        public static Stream GetQrcodeStream(string qrCode)
        {
            Gma.QrCodeNet.Encoding.QrEncoder Encoder = new Gma.QrCodeNet.Encoding.QrEncoder(Gma.QrCodeNet.Encoding.ErrorCorrectionLevel.H);
            Gma.QrCodeNet.Encoding.QrCode    Code    = Encoder.Encode(qrCode);
            GraphicsRenderer renderer = new GraphicsRenderer(new FixedModuleSize(10, QuietZoneModules.Two), System.Drawing.Brushes.Black, System.Drawing.Brushes.White);
            var stream = new MemoryStream();

            renderer.WriteToStream(Code.Matrix, System.Drawing.Imaging.ImageFormat.Png, stream);
            stream.Position = 0;
            return(stream);
        }
Esempio n. 5
0
        public static void GenerateQrCode(string qrCode)
        {
            Gma.QrCodeNet.Encoding.QrEncoder Encoder = new Gma.QrCodeNet.Encoding.QrEncoder(Gma.QrCodeNet.Encoding.ErrorCorrectionLevel.H);
            Gma.QrCodeNet.Encoding.QrCode    Code    = Encoder.Encode(qrCode);

            GraphicsRenderer renderer = new GraphicsRenderer(new FixedModuleSize(10, QuietZoneModules.Two), System.Drawing.Brushes.Black, System.Drawing.Brushes.White);

            using (FileStream stream = new FileStream($"{Path.Combine(ApplicationPath(), "Images", "QrCodes")}\\{qrCode}.png", FileMode.Create))
            {
                renderer.WriteToStream(Code.Matrix, System.Drawing.Imaging.ImageFormat.Png, stream);
            }
        }
        public recieve_bitcoincash()
        {
            InitializeComponent();

            IBitcoinService bitcoinService = new BitcoinService();
            string          a = bitcoinService.GetNewAddress();

            address_textBox.Text = a;


            Gma.QrCodeNet.Encoding.QrEncoder Encoder = new Gma.QrCodeNet.Encoding.QrEncoder(Gma.QrCodeNet.Encoding.ErrorCorrectionLevel.H);
            Gma.QrCodeNet.Encoding.QrCode    Code    = Encoder.Encode(a);
            Bitmap TempBMP = new Bitmap(Code.Matrix.Width, Code.Matrix.Height);

            for (int X = 0; X <= (Code.Matrix.Width) - 1; X++)
            {
                for (int Y = 0; Y <= (Code.Matrix.Height) - 1; Y++)
                {
                    if (Code.Matrix.InternalArray[X, Y])
                    {
                        TempBMP.SetPixel(X, Y, System.Drawing.Color.Black);
                    }
                    else
                    {
                        TempBMP.SetPixel(X, Y, System.Drawing.Color.White);
                    }
                }
            }

            //TempBMP.Size abc = new System.Drawing.Size(120,120);

            //Console.Write(TempBMP);
            //ictureBox.Image.Size =new  Size(600, 700);
            //empBMP.Size = new Size(TempBMP.Height,TempBMP.Width);
            pictureBox.Size = new Size(100, 75);
            // pictureBox.Image = TempBMP;

            var imageTemp = new Bitmap(TempBMP);

            var image = new Bitmap(imageTemp, new System.Drawing.Size(new System.Drawing.Point(100, 75)));

            //image.Save("file.bmp", ImageFormat.Bmp);

            pictureBox.Image = image;
        }
Esempio n. 7
0
        // QR Code를 bitmap으로 생성하여 리턴한다
        public static Bitmap GenerateQRCode(string text, System.Drawing.Color DarkColor, System.Drawing.Color LightColor)
        {
            Gma.QrCodeNet.Encoding.QrEncoder Encoder = new Gma.QrCodeNet.Encoding.QrEncoder(Gma.QrCodeNet.Encoding.ErrorCorrectionLevel.L);
            Gma.QrCodeNet.Encoding.QrCode    Code    = Encoder.Encode(text);
            Bitmap TempBMP = new Bitmap(Code.Matrix.Width, Code.Matrix.Height);

            for (int X = 0; X <= Code.Matrix.Width - 1; X++)
            {
                for (int Y = 0; Y <= Code.Matrix.Height - 1; Y++)
                {
                    if (Code.Matrix.InternalArray[X, Y])
                    {
                        TempBMP.SetPixel(X, Y, DarkColor);
                    }
                    else
                    {
                        TempBMP.SetPixel(X, Y, LightColor);
                    }
                }
            }
            return(TempBMP);
        }
Esempio n. 8
0
 public void UT_EncodeTest()
 {
     string url = "http://teal.azurewebsites.net/Event/1/1";
     var encoder = new Gma.QrCodeNet.Encoding.QrEncoder(Gma.QrCodeNet.Encoding.ErrorCorrectionLevel.M);
     var code = encoder.Encode(url);
     var bmp = new Bitmap(code.Matrix.Width, code.Matrix.Height);
     for (int x = 0; x < code.Matrix.Width; x++)
     {
         for (int y = 0; y < code.Matrix.Height; y++)
         {
             if (code.Matrix.InternalArray[x, y])
             {
                 bmp.SetPixel(x, y, Color.Black);
             }
             else
             {
                 bmp.SetPixel(x, y, Color.White);
             }
         }
     }
     bmp.Save("bmp.png", ImageFormat.Png);
 }
Esempio n. 9
0
        public void UT_EncodeTest()
        {
            string url     = "http://teal.azurewebsites.net/Event/1/1";
            var    encoder = new Gma.QrCodeNet.Encoding.QrEncoder(Gma.QrCodeNet.Encoding.ErrorCorrectionLevel.M);
            var    code    = encoder.Encode(url);
            var    bmp     = new Bitmap(code.Matrix.Width, code.Matrix.Height);

            for (int x = 0; x < code.Matrix.Width; x++)
            {
                for (int y = 0; y < code.Matrix.Height; y++)
                {
                    if (code.Matrix.InternalArray[x, y])
                    {
                        bmp.SetPixel(x, y, Color.Black);
                    }
                    else
                    {
                        bmp.SetPixel(x, y, Color.White);
                    }
                }
            }
            bmp.Save("bmp.png", ImageFormat.Png);
        }
Esempio n. 10
0
        /// <summary>
        /// Generates a bitmap with a QRCode encoding provided string
        /// </summary>
        /// <param name="text">String to encode.</param>
        /// <param name="size">The size of the QR code to generate</param>
        /// <returns>Bitmap with a QRCode encoding provided string</returns>
        public static Image GenerateQRBitmap(string text, int size)
        {
            Gma.QrCodeNet.Encoding.BitMatrix matrix = encoder.Encode(text).Matrix;
            int pixelSize = Math.Max(1, size / Math.Min(matrix.Height, matrix.Width));

            size = pixelSize * Math.Min(matrix.Height, matrix.Width);
            Bitmap   bmp = new Bitmap(size, size);
            Graphics g   = Graphics.FromImage(bmp);

            for (int i = 0; i < matrix.Width; ++i)
            {
                for (int j = 0; j < matrix.Width; ++j)
                {
                    g.FillRectangle(
                        matrix[i, j] ? Brushes.Black : Brushes.White,
                        i * pixelSize,
                        j * pixelSize,
                        pixelSize,
                        pixelSize);
                }
            }
            return(bmp);
        }