Exemplo n.º 1
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            var barcodeWriter = new BarcodeWriter
            {
                Format = ZXing.BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions
                {
                    Width = 300,
                    Height = 300,
                    Margin = 30
                }
            };

            var image = barcodeWriter.Write("ZXing.Net.Mobile");

            imageBarcode.Source = image;
        }
Exemplo n.º 2
0
        public static void Demonstration()
        {
            BarcodeWriter writer = new BarcodeWriter();

            writer.Format = BarcodeFormat.QR_CODE;
            QrCodeEncodingOptions options = new QrCodeEncodingOptions();

            options.DisableECI = true;
            //设置内容编码
            options.CharacterSet = "UTF-8";
            //设置二维码的宽度和高度
            options.Width  = 70;
            options.Height = 70;
            //设置二维码的边距,单位不是固定像素
            options.Margin = 1;
            writer.Options = options;

            using (Bitmap img = writer.Write("111111111-20C1601"))
            {
                img.Save($"{DateTime.Now.ToString("yyyyMMddHHmmss")}.png", ImageFormat.Png);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 生成一维条形码
        /// </summary>
        /// <param name="text">内容</param>
        /// <param name="height">高度</param>
        /// <returns></returns>
        public static Bitmap Barcode(string text, int height)
        {
            BarcodeWriter writer = new BarcodeWriter()
            {
            };

            //使用ITF 格式,不能被现在常用的支付宝、微信扫出来
            //如果想生成可识别的可以使用 CODE_128 格式
            //writer.Format = BarcodeFormat.ITF;
            writer.Format = BarcodeFormat.CODE_39;
            EncodingOptions options = new EncodingOptions()
            {
                Height      = height,
                Margin      = 2,
                PureBarcode = true
            };

            writer.Options = options;
            Bitmap map = writer.Write(text);

            return(map);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 获取二维码图片
        /// </summary>
        /// <param name="param">二维码参数</param>
        /// <returns></returns>
        private Bitmap GetBitmap(QRCodeParam param)
        {
            BarcodeWriter <Bitmap> bitmapBarcodeWriter = new BarcodeWriter <Bitmap>()
            {
                Format  = BarcodeFormat.QR_CODE,
                Options = new QrCodeEncodingOptions()
                {
                    CharacterSet    = "UTF-8",
                    ErrorCorrection = _level,
                    Margin          = 2,
                    Width           = param.Size,
                    Height          = param.Size,
                },
                Renderer = new BitmapRenderer()
                {
                    Foreground = Color.FromName(param.Foreground.Name),
                    Background = Color.FromName(param.Background.Name)
                }
            };

            return(bitmapBarcodeWriter.Write(param.Content));
        }
Exemplo n.º 5
0
        //轉換成Base64
        public string CreateQRCode2( )
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream( );            //記憶流

            //創建QRCode
            BarcodeWriter writer = new BarcodeWriter {
                Format  = BarcodeFormat.QR_CODE,    //條碼類型
                Options = new ZXing.QrCode.QrCodeEncodingOptions {
                    Width        = 500,             //寬
                    Height       = 500,             //高
                    CharacterSet = "UTF-8"
                }
            };

            System.Drawing.Bitmap bitmap = writer.Write("123");            //QRCode寫入字串

            bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);      //點陣圖以jpeg格式寫入到記憶流裡

            byte[] arr = ms.ToArray();

            return(Convert.ToBase64String(arr));
        }
Exemplo n.º 6
0
        /// <summary>
        /// 生成二维码图片
        /// </summary>
        /// <param name="strMessage">要生成二维码的字符串</param>
        /// <param name="width">二维码图片宽度</param>
        /// <param name="height">二维码图片高度</param>
        /// <returns></returns>
        private Bitmap GetQRCodeByZXingNet(String strMessage, Int32 width, Int32 height)
        {
            Bitmap result = null;

            try
            {
                BarcodeWriter barCodeWriter = new BarcodeWriter();
                barCodeWriter.Format = BarcodeFormat.QR_CODE;
                barCodeWriter.Options.Hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8");
                barCodeWriter.Options.Hints.Add(EncodeHintType.ERROR_CORRECTION, ZXing.QrCode.Internal.ErrorCorrectionLevel.H);
                barCodeWriter.Options.Height = height;
                barCodeWriter.Options.Width  = width;
                barCodeWriter.Options.Margin = 0;
                ZXing.Common.BitMatrix bm = barCodeWriter.Encode(strMessage);
                result = barCodeWriter.Write(bm);
            }
            catch (Exception)
            {
                //异常输出
            }
            return(result);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 生成二维码图片
        /// </summary>
        /// <param name="codeNumber">要生成二维码的字符串</param>
        /// <param name="size">大小尺寸</param>
        /// <returns>二维码图片</returns>
        public Bitmap Create_ImgCode(string codeNumber, int size)
        {
            BarcodeWriter writer = new BarcodeWriter();

            writer.Format = BarcodeFormat.CODE_128;
            QrCodeEncodingOptions options = new QrCodeEncodingOptions();

            options.PureBarcode = true;
            options.DisableECI  = true;
            //设置内容编码
            options.CharacterSet = "UTF-8";
            //设置二维码的宽度和高度
            options.Width  = size;
            options.Height = size;
            //设置二维码的边距,单位不是固定像素
            options.Margin = 0;
            writer.Options = options;

            Bitmap map = writer.Write(codeNumber);

            return(map);
        }
Exemplo n.º 8
0
        static void buildpdf(Client cl, String FileName, string text)
        {
            string var    = cl.getdata(ref text);
            var    writer = new BarcodeWriter
            {
                Format = BarcodeFormat.AZTEC
            };

            using (var bitmap = writer.Write(var))
            {
                bitmap.Save(FileName + ".png");
            }

            PdfDocument doc  = new PdfDocument();
            PdfPage     page = doc.AddPage();
            XGraphics   gfx  = XGraphics.FromPdfPage(page);

            XFont          font = new XFont("Verdana", 15, XFontStyle.Bold);
            XTextFormatter tf   = new XTextFormatter(gfx);
            XImage         img  = XImage.FromFile(FileName + ".png");

            gfx.DrawImage(img, 200, 50, 200, 200);
            img.Dispose();

            XRect rect = new XRect(220, 280, 200, 100);

            gfx.DrawRectangle(XBrushes.Transparent, rect);
            tf.DrawString(text, font, XBrushes.Black, rect, XStringFormats.TopLeft);
            gfx.DrawString("Have a nice flight", font, XBrushes.Black, 240, 400);

            img = XImage.FromFile("logo.png");
            gfx.DrawImage(img, 200, 420, 180, 82);
            doc.Save(FileName + ".pdf");

            page.Close();
            img.Dispose();
            gfx.Dispose();
            doc.Close();
        }
        private void UpdateBarcodeBitmapImage()
        {
            BarcodeWriter writer = new BarcodeWriter();
            Bitmap        bitmap = null;

            writer.Format  = BarcodeFormat.CODE_128;
            writer.Options = new ZXing.Common.EncodingOptions()
            {
                PureBarcode = true,
                Height      = 100,
                Width       = 280,
                Margin      = 10
            };

            try
            {
                bitmap = writer.Write(_barcodeContent ?? "");
            }
            catch { }

            BarcodeBitmap = ConvertBitmapToBitmapImage(bitmap);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 获取二维码图片
        /// </summary>
        /// <param name="content">内容</param>
        /// <returns></returns>
        private Bitmap GetBitmap(string content)
        {
            BarcodeWriter <Bitmap> bitmapBarcodeWriter = new BarcodeWriter <Bitmap>()
            {
                Format  = BarcodeFormat.QR_CODE,
                Options = new QrCodeEncodingOptions()
                {
                    CharacterSet    = "UTF-8",
                    ErrorCorrection = _level,
                    Margin          = _margin,
                    Width           = _size,
                    Height          = _size,
                },
                Renderer = new BitmapRenderer()
                {
                    Foreground = Color.FromName(_foregroundColor.Name),
                    Background = Color.FromName(_backgroundColor.Name)
                }
            };

            return(bitmapBarcodeWriter.Write(content));
        }
Exemplo n.º 11
0
        public override void draw(Graphics canvas)
        {
            var writer = new BarcodeWriter();

            writer.Format  = BarcodeFormat.QR_CODE;
            writer.Options = new QrCodeEncodingOptions
            {
                DisableECI   = true,
                CharacterSet = "UTF-8",
                Width        = 500,
                Height       = 500,
            };
            string s = fixedText();

            if (s == "")
            {
                s = "???";
            }
            Bitmap bmp = new Bitmap(writer.Write(s.Trim()));

            canvas.DrawImage(bmp, X - size / 2, Y - size / 2, size, size);
        }
Exemplo n.º 12
0
        public void Print(FlowDocument doc)
        {
            //var pd = new PrintDialog();
            //if (pd.ShowDialog() == true)
            //{
            //    pd.PrintDocument(((IDocumentPaginatorSource)doc).DocumentPaginator, "printing");
            //}
            var options = new EncodingOptions
            {
                Width  = 250,
                Height = 100,
            };
            var w = new BarcodeWriter
            {
                Options = options,
                Format  = BarcodeFormat.EAN_13,
            };

            var matr = w.Write("1000000000009");

            matr.Save(@"e:\1.png", ImageFormat.Png);
        }
Exemplo n.º 13
0
        /// <summary>
        /// 使用ZxingNet生成二维码图片
        /// </summary>
        /// <param name="imgPath">图片路径</param>
        /// <param name="codeContent">内容信息</param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="imgType">ImageFormat imgType</param>
        /// <param name="BarcodeFormat barcodeFormat">barcodeFormat</param>
        /// <returns></returns>
        public string NewQRCodeByZxingNet(string imgPath, string codeContent, int width, int height,
                                          ImageFormat imgType, BarcodeFormat barcodeFormat)
        {
            // 1.设置QR二维码的规格
            QrCodeEncodingOptions code = new QrCodeEncodingOptions();

            code.CharacterSet = "UTF-8"; // 设置编码格式,否则读取'中文'乱码
            code.Height       = height;
            code.Width        = width;
            code.Margin       = 1; // 设置周围空白边距

            // 2.生成条形码图片并保存
            BarcodeWriter wr = new BarcodeWriter();

            wr.Format  = barcodeFormat; // 二维码 BarcodeFormat.QR_CODE
            wr.Options = code;
            Bitmap img = wr.Write(codeContent);

            img.Save(imgPath, imgType);

            return(imgPath);
        }
Exemplo n.º 14
0
        // 【生成二维码】
        private void Create2DBtn_Click(object sender, EventArgs e)
        {
            // 1.设置QR二维码的规格
            ZXing.QrCode.QrCodeEncodingOptions qrEncodeOption = new ZXing.QrCode.QrCodeEncodingOptions();
            qrEncodeOption.CharacterSet = "UTF-8"; // 设置编码格式,否则读取'中文'乱码
            qrEncodeOption.Height = 200;
            qrEncodeOption.Width = 200;
            qrEncodeOption.Margin = 1; // 设置周围空白边距

            // 2.生成条形码图片并保存
            ZXing.BarcodeWriter wr = new BarcodeWriter();
            wr.Format = BarcodeFormat.QR_CODE; // 二维码 
            wr.Options = qrEncodeOption;
            Bitmap img = wr.Write(this.ContentTxt.Text);
            string filePath = "G:\\pics\\二维码" + "\\QR-" + this.ContentTxt.Text + ".jpg";
            img.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);

            // 3.读取保存的图片
            this.ImgPathTxt.Text = filePath;
            this.barCodeImg.Image = img;
            MessageBox.Show("保存成功:" + filePath);
        }
Exemplo n.º 15
0
        private void BtnGenerate_Click_1(object sender, EventArgs e)
        {
            BarcodeWriter   barcodeWriter   = new BarcodeWriter();
            EncodingOptions encodingOptions = new EncodingOptions()
            {
                Width       = 500,
                Height      = 500,
                Margin      = 0,
                PureBarcode = false
            };

            encodingOptions.Hints.Add(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
            barcodeWriter.Renderer = new BitmapRenderer();
            barcodeWriter.Options  = encodingOptions;
            barcodeWriter.Format   = BarcodeFormat.QR_CODE;
            Bitmap   bitmap = barcodeWriter.Write(textBox1.Text);
            Bitmap   logo   = new Bitmap($"I:/Programming/C#/QR_Image/pstu.png");
            Graphics g      = Graphics.FromImage(bitmap);

            g.DrawImage(logo, new Point((bitmap.Width - logo.Width) / 2, (bitmap.Height - logo.Height) / 2));
            this.pictureBox1.Image = bitmap;
        }
Exemplo n.º 16
0
        private void button1_Click(object sender, EventArgs e)
        {
            var QCwriter = new BarcodeWriter();

            QCwriter.Format = BarcodeFormat.QR_CODE;
            var    result        = QCwriter.Write(textBox1.Text);
            string path          = "C:/Users/Administrator/Desktop/QRimage.jpg";
            var    barcodeBitmap = new Bitmap(result);

            using (MemoryStream memory = new MemoryStream())
            {
                using (FileStream fs = new FileStream(path,
                                                      FileMode.Create, FileAccess.ReadWrite))
                {
                    barcodeBitmap.Save(memory, ImageFormat.Jpeg);
                    byte[] bytes = memory.ToArray();
                    fs.Write(bytes, 0, bytes.Length);
                }
            }

            MessageBox.Show("QR code is generated..");
        }
Exemplo n.º 17
0
        /// <summary>
        /// 创建条形码
        /// </summary>
        /// <param name="contents">要生成条形码包含的信息</param>
        /// <param name="barPath">生成的条形码路径</param>
        /// <param name="width">条形码宽度</param>
        /// <param name="height">条形码高度</param>
        /// <returns>bool</returns>
        public static bool CreateBar(string contents, string barPath, int width = 150, int height = 50)
        {
            var res = false;

            try
            {
                if (!string.IsNullOrEmpty(contents))
                {
                    var writer = new BarcodeWriter
                    {
                        //使用ITF 格式,不能被现在常用的支付宝、微信扫出来
                        //如果想生成可识别的可以使用 CODE_128 格式
                        //writer.Format = BarcodeFormat.ITF;
                        Format  = BarcodeFormat.CODE_128,
                        Options = new EncodingOptions
                        {
                            Width  = width,
                            Height = height,
                            Margin = 2
                        }
                    };
                    using (var bitmap = writer.Write(contents))
                    {
                        if (File.Exists(barPath))
                        {
                            File.Delete(barPath);
                        }
                        bitmap.Save(barPath);
                        res = true;
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex, "创建条形码");
                res = false;
            }
            return(res);
        }
Exemplo n.º 18
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            BarcodeFormat   myBarcodeFormat;
            EncodingOptions myEncoding;

            if (this.CodeType == 1)//二维码
            {
                myBarcodeFormat = BarcodeFormat.QR_CODE;
                myEncoding      = new QrCodeEncodingOptions()
                {
                    Height       = this.Height,
                    Width        = this.Width,
                    Margin       = 0,
                    CharacterSet = "UTF-8",
                    PureBarcode  = !this.IsShowText
                };
            }
            else//条形码
            {
                myBarcodeFormat = BarcodeFormat.CODE_128;
                myEncoding      = new EncodingOptions()
                {
                    Height      = this.Height,
                    Width       = this.Width,
                    Margin      = 0,
                    PureBarcode = !this.IsShowText
                };
            }
            BarcodeWriter writer = new BarcodeWriter
            {
                Format   = myBarcodeFormat,
                Options  = myEncoding,
                Renderer = (IBarcodeRenderer <Bitmap>)Activator.CreateInstance(typeof(BitmapRenderer))
            };
            Bitmap barImg = writer.Write(this.Content);

            e.Graphics.DrawImage(barImg, 0, 0, this.Width, this.Height);
        }
Exemplo n.º 19
0
    public static void GenerateQRImage(RawImage QRCodeImage, string content, int width, int height)
    {
        EncodingOptions options = null;
        BarcodeWriter   writer  = new BarcodeWriter();

        options = new EncodingOptions
        {
            Width  = width,
            Height = height,
            Margin = 1,
        };
        options.Hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8");
        writer.Format  = BarcodeFormat.QR_CODE;
        writer.Options = options;
        Color32[] colors = writer.Write(content);

        Texture2D texture = new Texture2D(width, height);

        texture.SetPixels32(colors);
        texture.Apply();
        QRCodeImage.texture = texture;
    }
Exemplo n.º 20
0
        void getBarCode(string data)
        {
            BarcodeWriter wr = new BarcodeWriter();

            wr.Format = BarcodeFormat.CODE_93;

            System.IO.MemoryStream ms = new System.IO.MemoryStream();

            wr.Write(data).Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            //create directory to save the image

            if (!Directory.Exists(@"C:\" + dirname))
            {
                Directory.CreateDirectory(@"C:\" + dirname);
            }

            Bitmap bmp = new Bitmap(ms);

            bmp.Save(@"C:\" + dirname + "\\" + dirname + ".jpg");

            //return bmp;
        }
        ///<summary>

        ///生成条形码

        ///</summary>

        ///<paramname="pictureBox1"></param>

        ///<paramname="Contents"></param>

        public void CreateBarCode(PictureBox pictureBox1, string Contents)

        {
            Regex rg = new Regex("^[0-9]{12}$");

            if (!rg.IsMatch(Contents))

            {
                MessageBox.Show("本例子采用EAN_13编码,需要输入12位数字");

                return;
            }



            EncodingOptions options = null;

            BarcodeWriter writer = null;

            options = new EncodingOptions

            {
                Width = pictureBox1.Width,

                Height = pictureBox1.Height
            };

            writer = new BarcodeWriter();

            writer.Format = BarcodeFormat.ITF;

            writer.Options = options;



            Bitmap bitmap = writer.Write(Contents);

            pictureBox1.Image = bitmap;
        }
Exemplo n.º 22
0
        /// <summary>
        /// 生成二维码,保存成图片(CodeImage.QrCode(@"F:\qrcode.png", "123"))
        /// </summary>
        /// <param name="filename">生成保存的文件绝对路径</param>
        /// <param name="content">二维码内容</param>
        public static void QrCode(string filename, string content, int Width = 500, int Height = 500)
        {
            BarcodeWriter writer = new BarcodeWriter();

            writer.Format = BarcodeFormat.QR_CODE;
            QrCodeEncodingOptions options = new QrCodeEncodingOptions();

            options.DisableECI = true;
            //设置内容编码
            options.CharacterSet = "UTF-8";
            //设置二维码的宽度和高度
            options.Width  = Width;
            options.Height = Height;
            //设置二维码的边距,单位不是固定像素
            options.Margin = 1;
            writer.Options = options;

            Bitmap map = writer.Write(content);

            map.Save(filename, ImageFormat.Png);
            map.Dispose();
        }
Exemplo n.º 23
0
        /// <summary>
        ///     Формирования баркода выбранным алгоритмом
        ///     Кодируемые и декодированные данные передаются через аттрибуты класса
        /// </summary>
        public Bitmap Encode()
        {
            int count      = Marshal.SizeOf(typeof(BinaryData));
            var binaryData = new BinaryData
            {
                ArchiverIndex = (byte)ArchiverIndex,
                MixerIndex    = (byte)MixerIndex,
                GammaIndex    = (byte)GammaIndex,
                EccIndex      = (byte)EccIndex,
                ExpandSize    = (byte)ExpandSize,
                EccCodeSize   = (byte)EccCodeSize,
                EccDataSize   = (byte)EccDataSize,
                MaximumGamma  = (byte)(MaximumGamma ? 0 : -1),
            };

            byte[] keyBytes    = Encoding.Default.GetBytes(Key);
            var    binaryBytes = new byte[count];
            IntPtr ptr         = Marshal.AllocHGlobal(binaryBytes.Length);

            Marshal.StructureToPtr(binaryData, ptr, true);
            Marshal.Copy(ptr, binaryBytes, 0x0, binaryBytes.Length);
            Marshal.FreeHGlobal(ptr);
            string text = Convert.ToBase64String(binaryBytes.Concat(keyBytes).ToArray());

            switch (_barcodeId)
            {
            case 0:
                throw new ArgumentNullException();

            default:
                var writer = new BarcodeWriter
                {
                    Format = (BarcodeFormat)_barcodeId,
                };
                Bitmap result = writer.Write(text);
                using (var image = new Image <Gray, Byte>(result))
                    return(_bitmap = image.Bitmap);
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// Genera un codigo de barras a partir de la data especificada y lo guarda como imagen en formato .png
        /// </summary>
        /// <param name="data">Los datos que se van a codificar.</param>
        /// <param name="fullPathDirectory">El directorio de salida de la imagen.</param>
        /// <returns>Devuelve un número entero positivo o negativo.</returns>
        public int GenerateBarCodeAsPNG(string data, string fullPathDirectory, bool rotate)
        {
            try
            {
                var directory = fullPathDirectory.Substring(fullPathDirectory.Length - 1, 1) != "\\" ? fullPathDirectory = fullPathDirectory + "\\" : fullPathDirectory;

                string fileName = $"{directory}barCode.png";
                var    barCode  = BarcodeWriter.CreateBarcode(data, BarcodeEncoding.Code128);
                var    result   = barCode.SaveAsPng(fileName);

                if (rotate)
                {
                    DocumentProcessor.RotateImage(result.ToBitmap(), fileName);
                }

                return((int)TypesEvent.SuccessProccess);
            }
            catch (IronBarCodeEncodingException encex)
            {
                var message = encex.Message;

                if (message.Contains("Bad character in input"))
                {
                    return((int)TypesEvent.BadCharacter);
                }
                else if (message.Contains("Contents length should be between 1 and 80 characters"))
                {
                    return((int)TypesEvent.ContentLength);
                }
                else
                {
                    return((int)TypesEvent.ErrorGeneric);
                }
            }
            catch (Exception)
            {
                return((int)TypesEvent.ErrorGeneric);
            }
        }
Exemplo n.º 25
0
 private void renderQR(String text)
 {
     Renderer = typeof(BitmapRenderer);
     try
     {
         var writer = new BarcodeWriter
         {
             Format  = BarcodeFormat.QR_CODE,
             Options = new ZXing.Common.EncodingOptions
             {
                 Height = qrBox.Height,
                 Width  = qrBox.Width
             },
             Renderer = (IBarcodeRenderer <Bitmap>)Activator.CreateInstance(Renderer)
         };
         qrBox.Image = writer.Write(text);
     }
     catch (Exception exc)
     {
         MessageBox.Show(this, exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemplo n.º 26
0
        public static IHtmlString GenerateQrCode(this HtmlHelper html, string url, string alt = "QR code", int height = 100, int width = 100, int margin = 0)
        {
            var qrWriter = new BarcodeWriter();

            qrWriter.Format  = BarcodeFormat.QR_CODE;
            qrWriter.Options = new EncodingOptions()
            {
                Height = height, Width = width, Margin = margin
            };

            using (var q = qrWriter.Write(url))
            {
                using (var ms = new MemoryStream())
                {
                    q.Save(ms, ImageFormat.Png);
                    var img = new TagBuilder("img");
                    img.Attributes.Add("src", String.Format("data:image/png;base64,{0}", Convert.ToBase64String(ms.ToArray())));
                    img.Attributes.Add("alt", alt);
                    return(MvcHtmlString.Create(img.ToString(TagRenderMode.SelfClosing)));
                }
            }
        }
Exemplo n.º 27
0
        public override bool WriteCoinToBARCode(CloudCoin cloudCoin, string OutputFile, string tag)
        {
            var writer = new BarcodeWriter
            {
                Format  = BarcodeFormat.PDF_417,
                Options = new EncodingOptions {
                    Width = 200, Height = 50
                }                                                          //optional
            };

            cloudCoin.pan = null;
            var coinJson  = JsonConvert.SerializeObject(cloudCoin);
            var imgBitmap = writer.Write(coinJson);

            using (var stream = new MemoryStream())
            {
                imgBitmap.Save(stream, ImageFormat.Png);
                stream.ToArray();
                imgBitmap.Save(OutputFile);
            }
            return(true);
        }
Exemplo n.º 28
0
        /// <summary>
        /// 生成条形码并保存
        /// </summary>
        /// <param name="Content">条形码内容</param>
        /// <param name="SavePath">存储路径</param>
        /// <param name="ImageFormat">生成二维码图片的格式</param>
        public static void CreateBarCode(string Content, string SavePath, ImageFormat ImageFormat)
        {
            BarcodeWriter writer = new BarcodeWriter();

            //使用ITF 格式,不能被现在常用的支付宝、微信扫出来
            //如果想生成可识别的可以使用 CODE_128 格式
            //writer.Format = BarcodeFormat.ITF;
            writer.Format = BarcodeFormat.CODE_128;
            EncodingOptions options = new EncodingOptions()
            {
                Width  = 150,
                Height = 50,
                Margin = 2
            };

            writer.Options = options;
            Bitmap map = writer.Write(Content);

            map.Save(SavePath, ImageFormat);
            map.Dispose();
            map = null;
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            NavigationItem.Title = "Generate Barcode";

            var barcodeWriter = new BarcodeWriter
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions
                {
                    Width  = 280,
                    Height = 280
                }
            };

            var barcode = barcodeWriter.Write("Basel AbuBaker");

            imageBarcode.Image = barcode;

            btnBack.TouchUpInside += BtnBack_TouchUpInside;
        }
Exemplo n.º 30
0
        //生成条形码
        private void btnEncodeBarCode_Click(object sender, EventArgs e)
        {
            try
            {
                // 1.设置条形码规格
                EncodingOptions encodeOption = new EncodingOptions();
                encodeOption.Height = CodeHeight; // 必须制定高度、宽度
                encodeOption.Width  = CodeMethod;

                // 2.生成条形码图片并保存
                BarcodeWriter wr = new BarcodeWriter();
                wr.Options = encodeOption;
                var format = BarcodeFormatHelper.GetFormat(this.cbEncodeType.SelectedItem.ToString());
                wr.Format    = format;                      //  条形码规格:EAN13规格:12(无校验位)或13位数字
                BarCodeImage = wr.Write(this.txtData.Text); // 生成图片
                this.barcode.BackgroundImage = BarCodeImage;
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "Exception", MessageBoxButtons.OK);
            }
        }
Exemplo n.º 31
0
    private byte[] GenerateQRCode(string qrcodeText)
    {
        SqlConnection con = new SqlConnection(dbc.consString);

        con.Open();
        var    sql           = string.Empty;
        string folderPath    = HttpContext.Current.Server.MapPath("~/content/images/");
        string imagePath     = HttpContext.Current.Server.MapPath("~/content/images/QrCode.png");
        var    barcodeWriter = new BarcodeWriter();

        barcodeWriter.Format = BarcodeFormat.QR_CODE;
        var    result = barcodeWriter.Write(qrcodeText);
        int    width = 200, height = 200;
        string barcodePath   = imagePath;
        var    barcodeBitmap = new Bitmap(result, height, width);

        byte[] bytes = new byte[1024];

        try
        {
            using (MemoryStream memory = new MemoryStream())
            {
                using (FileStream fs = File.Create(barcodePath, 1024))
                {
                    barcodeBitmap.Save(memory, ImageFormat.Png);
                    bytes = memory.ToArray();
                    fs.Write(bytes, 0, bytes.Length);
                }
                memory.Flush();
                memory.Close();
            }
        }
        catch (Exception ex)
        {
        }
        con.Close();
        return(bytes);
    }
Exemplo n.º 32
0
        public override void ViewDidLoad ()
        {
            base.ViewDidLoad ();

			View.BackgroundColor = UIColor.Gray;

			nfloat h = 31.0f;
			nfloat w = View.Bounds.Width;

			usernameField = new UITextField
			{
				Placeholder = "Enter your username",
				BorderStyle = UITextBorderStyle.RoundedRect,
				Frame = new CGRect(10, 82, w - 20, h)
			};

			View.AddSubview(usernameField);
            NavigationItem.Title = "Generate Barcode";

            imageBarcode = new UIImageView (new CGRect (220, 80, View.Frame.Width - 60, View.Frame.Height - 220));

            View.AddSubview (imageBarcode);

            var barcodeWriter = new BarcodeWriter {
                Format = ZXing.BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions {
                    Width = 300,
                    Height = 300,
                    Margin = 30
                }
            };

            var barcode = barcodeWriter.Write ("ZXing.Net.Mobile");

            imageBarcode.Image = barcode;
        }
Exemplo n.º 33
0
        public override void ViewDidLoad ()
        {
            base.ViewDidLoad ();

            NavigationItem.Title = "Generate Barcode";
            View.BackgroundColor = UIColor.White;

            imageBarcode = new UIImageView (new CGRect (20, 80, View.Frame.Width - 40, View.Frame.Height - 120));

            View.AddSubview (imageBarcode);

            var barcodeWriter = new BarcodeWriter {
                Format = ZXing.BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions {
                    Width = 300,
                    Height = 300,
                    Margin = 30
                }
            };

            var barcode = barcodeWriter.Write ("ZXing.Net.Mobile");

            imageBarcode.Image = barcode;
        }
Exemplo n.º 34
0
      public void test_Random_Encoding_Decoding_Cycles_Up_To_1000()
       {
           int bigEnough = 256;

           byte[] data = new byte[256];
           Random random = new Random(2344);

           for (int i = 0; i < 1000; i++)
           {
              random.NextBytes(data);
              //string content = "U/QcYPdz4MTR2nD2+vv88mZVnLA9/h+EGrEu3mwRIP65DlM6vLwlAwv/Ztd5LkHsio3UEJ29C1XUl0ZGRAFYv7pxPeyowjWqL5ilPZhICutvQlTePBBg+wP+ZiR2378Jp6YcB/FVRMdXKuAEGM29i41a1gKseYKpEEHpqlwRNE/Zm5bxKwL5Gv2NhxIvXOM1QNqWGwm9XC0jcvawbJprRfaRK3w3y2CKYbwEH/FwerRds2mBehhFHD5ozbgLSa1iIkIbnjBn/XV6DLpNuD08s/hCUrgx6crdSw89z/2nfxcOov2vVNuE9rbzB25e+GQBLBq/yfb1MTh3PlMhKS530w==";
              string content = Convert.ToBase64String(data);

              BarcodeWriter writer = new BarcodeWriter
                 {
                    Format = BarcodeFormat.QR_CODE,
                    Options = new EncodingOptions
                       {
                          Height = bigEnough,
                          Width = bigEnough
                       }
                 };
              Bitmap bmp = writer.Write(content);

              var reader = new BarcodeReader
                 {
                    Options = new DecodingOptions
                       {
                          PureBarcode = true,
                          PossibleFormats = new List<BarcodeFormat> {BarcodeFormat.QR_CODE}
                       }
                 };
              var decodedResult = reader.Decode(bmp);

              Assert.IsNotNull(decodedResult);
              Assert.AreEqual(content, decodedResult.Text);
           }
       }
Exemplo n.º 35
0
 public PixelData ToBitmap()
 {
    var writer = new BarcodeWriter { Format = BarcodeFormat.EAN_8 };
    return writer.Write(this);
 }
Exemplo n.º 36
0
 public Bitmap ToBitmap(BarcodeFormat format, String content)
 {
     var writer = new BarcodeWriter { Format = format };
     return writer.Write(content);
 }