当前位置: 首页>>代码示例>>C#>>正文


C# ZXing.BarcodeWriter类代码示例

本文整理汇总了C#中ZXing.BarcodeWriter的典型用法代码示例。如果您正苦于以下问题:C# BarcodeWriter类的具体用法?C# BarcodeWriter怎么用?C# BarcodeWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BarcodeWriter类属于ZXing命名空间,在下文中一共展示了BarcodeWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawCode

 static void DrawCode(string code, ImageView barcode)
 {
     var writer = new BarcodeWriter
     {
         Format = BarcodeFormat.CODE_39,
         Options = new EncodingOptions
         {
             Height = 200,
             Width = 600
         }
     };
     var bitmap = writer.Write(code);
     Drawable img = new BitmapDrawable(bitmap);
     barcode.SetImageDrawable(img);
 }
开发者ID:TheDemx27,项目名称:PVRSBarcode,代码行数:15,代码来源:MainActivity.cs

示例2: ToImage

 /// <summary>
 /// 
 /// </summary>
 /// <param name="code"></param>
 /// <param name="size"></param>
 /// <returns></returns>
 public static Bitmap ToImage(string code, int size = 180)
 {
     BarcodeWriter writer = new BarcodeWriter();
     QrCodeEncodingOptions qr = new QrCodeEncodingOptions()
     {
         CharacterSet = "UTF-8",
         ErrorCorrection = ZXing.QrCode.Internal.ErrorCorrectionLevel.H,
         Height = size,
         Width = size,
     };
     writer.Options = qr;
     writer.Format = BarcodeFormat.QR_CODE;
     Bitmap bitmap = writer.Write(code);
     return bitmap;
 }
开发者ID:ysjr-2002,项目名称:BJ-Benz,代码行数:21,代码来源:Barcode.cs

示例3: decodeBarcodeText

        private static string decodeBarcodeText(System.Drawing.Bitmap barcodeBitmap)
        {
            var source = new BitmapLuminanceSource(barcodeBitmap);

            // using http://zxingnet.codeplex.com/
            // PM> Install-Package ZXing.Net
            var reader = new BarcodeReader(null, null, ls => new GlobalHistogramBinarizer(ls))
            {
                AutoRotate = true,
                TryInverted = true,
                Options = new DecodingOptions
                {
                    TryHarder = true,
                    //PureBarcode = true,
                    /*PossibleFormats = new List<BarcodeFormat>
                    {
                        BarcodeFormat.CODE_128
                        //BarcodeFormat.EAN_8,
                        //BarcodeFormat.CODE_39,
                        //BarcodeFormat.UPC_A
                    }*/
                }
            };

            //var newhint = new KeyValuePair<DecodeHintType, object>(DecodeHintType.ALLOWED_EAN_EXTENSIONS, new Object());
            //reader.Options.Hints.Add(newhint);

            var result = reader.Decode(source);
            if (result == null)
            {
                Console.WriteLine("Decode failed.");
                return string.Empty;
            }

            Console.WriteLine("BarcodeFormat: {0}", result.BarcodeFormat);
            Console.WriteLine("Result: {0}", result.Text);

            var writer = new BarcodeWriter
            {
                Format = result.BarcodeFormat,
                Options = { Width = 200, Height = 50, Margin = 4},
                Renderer = new ZXing.Rendering.BitmapRenderer()
            };
            var barcodeImage = writer.Write(result.Text);
            Cv2.ImShow("BarcodeWriter", barcodeImage.ToMat());

            return result.Text;
        }
开发者ID:kauser-cse-buet,项目名称:OpenCVSharp-Samples,代码行数:48,代码来源:Program.cs

示例4: GenerateLinearCode

        public static IHtmlString GenerateLinearCode(this HtmlHelper html, string inputentry, int height = 210, int width = 900, int margin = 0)
        {
            var qrValue = inputentry;
            var barcodeWriter = new BarcodeWriter
            {
                Format = BarcodeFormat.CODE_39,
                Options = new EncodingOptions
                {
                    Height = height,
                    Width = width,
                    Margin = margin,
                    PureBarcode = true
                }
            };

            using (var bitmap = barcodeWriter.Write(qrValue))
            using (var stream = new MemoryStream())
            {
                bitmap.Save(stream, ImageFormat.Gif);

                var img = new TagBuilder("img");
                img.MergeAttribute("alt", "code39 barcode");
                img.Attributes.Add("src", String.Format("data:image/gif;base64,{0}",
                    Convert.ToBase64String(stream.ToArray())));

                return MvcHtmlString.Create(img.ToString(TagRenderMode.SelfClosing));
            }
        }
开发者ID:1feanyi,项目名称:MvcPhoenix_WIP,代码行数:28,代码来源:BarcodeExtensions.cs

示例5: GeneratorQrCodeImage

        /// <summary>
        /// 生成二维码图片
        /// </summary>
        /// <param name="contents">要生成二维码包含的信息</param>
        /// <param name="width">生成的二维码宽度(默认300像素)</param>
        /// <param name="height">生成的二维码高度(默认300像素)</param>
        /// <returns>二维码图片</returns>
        public static Bitmap GeneratorQrCodeImage(string contents, int width = 300, int height = 300)
        {
            if (string.IsNullOrEmpty(contents))
            {
                return null;
            }

            EncodingOptions options = null;
            BarcodeWriter writer = null;
            options = new QrCodeEncodingOptions
            {
                DisableECI = true,
                CharacterSet = "UTF-8",
                Width = width,
                Height = height,
                ErrorCorrection = ErrorCorrectionLevel.H,
                //控制二维码图片的边框
                Margin = 0
            };
            writer = new BarcodeWriter
            {
                Format = BarcodeFormat.QR_CODE,
                Options = options
            };

            Bitmap bitmap = writer.Write(contents);

            return bitmap;
        }
开发者ID:jinhonglin,项目名称:DotNetStudio,代码行数:36,代码来源:QrCodeHelper.cs

示例6: Create

		public virtual Stream Create(BarCodeCreateConfiguration cfg) {
#if __ANDROID__
            var writer = new ZXing.BarcodeWriter {
				Format = (BarcodeFormat)Enum.Parse(typeof(BarcodeFormat), cfg.Format.ToString()),
                Encoder = new MultiFormatWriter(),
                Options = new EncodingOptions {
					Height = cfg.Height,
					Margin = cfg.Margin,
					Width = cfg.Height,
					PureBarcode = cfg.PureBarcode
                }
            };
#endif
#if __IOS__
            var writer = new ZXing.Mobile.BarcodeWriter
            {
                Format = (BarcodeFormat)Enum.Parse(typeof(BarcodeFormat), cfg.Format.ToString()),
                Encoder = new MultiFormatWriter(),
                Options = new EncodingOptions
                {
                    Height = cfg.Height,
                    Margin = cfg.Margin,
                    Width = cfg.Height,
                    PureBarcode = cfg.PureBarcode
                }
            };
#endif
            return this.ToImageStream(writer, cfg);
        }
开发者ID:TorbenK,项目名称:barcodes,代码行数:29,代码来源:AbstractBarCodesImpl.cs

示例7: GenerateMatrixCodeLabelSm

        public static IHtmlString GenerateMatrixCodeLabelSm(this HtmlHelper html, string inputentry, int height = 144, int width = 144, int margin = 0)
        {
            var qrValue = inputentry + "          "; // 10 trailing spaces added to guard against unpredictabilty.
            var barcodeWriter = new BarcodeWriter
            {
                Format = BarcodeFormat.DATA_MATRIX,
                Options = new EncodingOptions
                {
                    Height = height,
                    Width = width,
                    Margin = margin
                }
            };

            using (var bitmap = barcodeWriter.Write(qrValue))
            using (var stream = new MemoryStream())
            {
                bitmap.Save(stream, ImageFormat.Gif);

                var img = new TagBuilder("img");
                img.MergeAttribute("alt", "matrix barcode");
                img.Attributes.Add("src", String.Format("data:image/gif;base64,{0}",
                    Convert.ToBase64String(stream.ToArray())));

                return MvcHtmlString.Create(img.ToString(TagRenderMode.SelfClosing));
            }
        }
开发者ID:1feanyi,项目名称:MvcPhoenix_WIP,代码行数:27,代码来源:BarcodeExtensions.cs

示例8: GetQrCodeImage

        public static BitmapSource GetQrCodeImage(string qrValue)
        {
            var barcodeWriter = new BarcodeWriter
            {
                Format = BarcodeFormat.QR_CODE,
                Options = new EncodingOptions
                {
                    Height = 300,
                    Width = 300,
                    Margin = 1
                }
            };

            using (var bMap = barcodeWriter.Write(qrValue))
            {
                var hbmp = bMap.GetHbitmap();
                try
                {
                    var source = Imaging.CreateBitmapSourceFromHBitmap(hbmp, IntPtr.Zero, Int32Rect.Empty,
                        BitmapSizeOptions.FromEmptyOptions());
                    // QRCode.Source = source;
                    // QrCodeImage = source;
                    return source;
                }
                finally
                {
                    // DeleteObject(hbmp); // TODO huh? what or where is DeleteObject ???

                }
            }
        }
开发者ID:jhalbrecht,项目名称:MyPictures,代码行数:31,代码来源:QrCodeUtility.cs

示例9: Update

        private async void Update()
        {
            var writer1 = new BarcodeWriter
            {
                Format = BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions
                {
                    Height = 200,
                    Width = 200
                },

            };

            var image = writer1.Write(Text);//Write(text);


            using (InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream())
            {
                using (DataWriter writer = new DataWriter(ms.GetOutputStreamAt(0)))
                {
                    writer.WriteBytes(image);
                    await writer.StoreAsync();
                }

                var output = new BitmapImage();
                await output.SetSourceAsync(ms);
                ImageSource = output;
            }


        }
开发者ID:smndtrl,项目名称:Signal-UWP,代码行数:31,代码来源:QrCode.xaml.cs

示例10: GetCode128

        public HttpResponseMessage GetCode128(string value, int? height = null)
        {
            if (value == null || value.Length == 1 || value.Length > 80) {
                var errorResponse = new HttpResponseMessage(HttpStatusCode.BadRequest) {
                    Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(new { Error = "Value must be between 1 and 80 characters." })),
                };
                return errorResponse;
            }

            var response = new HttpResponseMessage();
            var writer = new BarcodeWriter() {
                Format = BarcodeFormat.CODE_128,
            };
            if (height.HasValue) {
                writer.Options.Hints[ZXing.EncodeHintType.HEIGHT] = height.Value;
            }

            Bitmap barcodeBitmap = writer.Write(value);
            using (var pngStream = new MemoryStream()) {
                barcodeBitmap.Save(pngStream, ImageFormat.Png);
                response.Content = new ByteArrayContent(pngStream.ToArray());
                response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
                return response;
            }
        }
开发者ID:patridge,项目名称:zxingnetapi,代码行数:25,代码来源:BarcodeController.cs

示例11: Main

        static void Main(string[] args)
        {
            var parsedArgs = new Arguments();

            if (args.Length == 0)
            {
                Console.WriteLine(Parser.ArgumentsUsage(typeof(Arguments)));
                return;
            }

            if (!Parser.ParseArgumentsWithUsage(args, parsedArgs))
            {
                Console.WriteLine("Can't parse arguments");
                return;
            }

            var writer = new BarcodeWriter
                {
                    Format = BarcodeFormat.QR_CODE,
                    Options = new EncodingOptions
                        {
                            Height = parsedArgs.Size,
                            Width = parsedArgs.Size,
                            PureBarcode = true,
                            Margin = 0
                        },
                    Renderer = (IBarcodeRenderer<Bitmap>) Activator.CreateInstance(typeof (BitmapRenderer))
                };

            var bitmap = writer.Write(parsedArgs.Content);
            bitmap.SetResolution(parsedArgs.DPI, parsedArgs.DPI);
            bitmap.Save(parsedArgs.Output);
        }
开发者ID:kholodovitch,项目名称:code-to-qr,代码行数:33,代码来源:Program.cs

示例12: ViewDidLoad

        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();
            lblResult.Text = "";

            txInput.Text = "http://thinkpower.info/xamarin/cn/";

            //扫描条码
            btnScan.TouchUpInside += async (sender, e) => {
                var scanner = new ZXing.Mobile.MobileBarcodeScanner();
                var result = await scanner.Scan();

                if (result != null)
                    this.lblResult.Text = result.Text;
            };

            //产生条码
            btnGenerateBarCode.TouchUpInside += (sender, e) => {
                txInput.ResignFirstResponder();
                var writer = new BarcodeWriter
                {
                    Format = BarcodeFormat.QR_CODE

                };
                var bitmap = writer.Write(txInput.Text);
                this.img_code.Image = bitmap;
            };
        }
开发者ID:Terry-Lin,项目名称:MDCC,代码行数:28,代码来源:BarcodeiosViewController.cs

示例13: Generate

        private BarcodeGroup Generate(BarcodeWriter bw, BarcodeOptions options)//string ap, string dayFrom, string dayTo)
        {
            Random rndNumber = new Random();
            //	load flight details
            var flightResult = AccessGateFlightInfo.ToList().Where(x => x.FlightNo == options.FlightNo).ToList();
            //	If no result, return
            if (flightResult.Count == 0)
            {
                return new BarcodeGroup();
            }
            //	Make flight easier to access
            var flight = flightResult[0];
            var carrier = flight.CarrierDesignator;
            if (carrier.Length < 3)
                carrier = carrier.PadRight(3, ' ');
            var pnr = "";
            string name = options.Name.Length > 20 ? options.Name.Substring(0, 20) : options.Name.PadRight(20, ' ');

            var jDate = (flight.DepartDateTime.DayOfYear + 14).ToString().PadLeft(3, '0');
            var securityValue = name.ToArray().Sum(c => (int)c) + flight.FromAirport.ToArray().Sum(c => (int)c) + options.CISN.ToArray().Sum(c => (int)c);
            var r = (rndNumber).Next(100, 700).ToString();
            var securityFactor = Convert.ToInt32(r, 16);
            securityValue += securityFactor;
            pnr = string.Format("{0}{1}", securityFactor.ToString("X3"), securityValue.ToString("X4"));
            var d = ConfigurationManager.GetSAVConfigSetting("SmartAccessValidation", "CovertSerialNumber");
            var barcode = string.Format("M1{0}E{1}{10}{2}{3}{4}{5}Y{6}{7}01E0293[{8}To{9}]{11}", name, pnr, flight.ToAirport, carrier, flight.FlightNo, jDate, options.Seat, options.CISN, options.StartDate, options.EndDate, options.AP, (Convert.ToInt32(d.KeyValue) + 1).ToString().PadLeft(6, '0'));

            var bg = new BarcodeGroup
            {
                barcode = barcode,
                image = bw.Write(barcode)
            };

            return bg;
        }
开发者ID:MHAWeb,项目名称:MachSecure.CentralWebService,代码行数:35,代码来源:TestBarcodeGenerator.cs

示例14: GenerateRelayQrCode

        public static IHtmlString GenerateRelayQrCode(this HtmlHelper html, string alt, string value, int height = 250, int width = 250, int margin = 0)
        {
            var barcodeWriter = new BarcodeWriter
            {
                Format = BarcodeFormat.QR_CODE,
                Options = new EncodingOptions
                {
                    Height = height,
                    Width = width,
                    Margin = margin
                }
            };

            using (var bitmap = barcodeWriter.Write(value))
            using (var stream = new MemoryStream())
            {
                bitmap.Save(stream, ImageFormat.Gif);

                var img = new TagBuilder("img");
                img.MergeAttribute("alt", alt);
                img.Attributes.Add("src", String.Format("data:image/gif;base64,{0}",
                    Convert.ToBase64String(stream.ToArray())));

                return MvcHtmlString.Create(img.ToString(TagRenderMode.SelfClosing));
            }
        }
开发者ID:scottmetoyer,项目名称:event-attendance,代码行数:26,代码来源:HtmlHelperExtensions.cs

示例15: ProcessLabelItem

        private static void ProcessLabelItem(LabelItem labelItem, Graphics g, PrintLabelSettings settings)
        {
            switch (labelItem.LabelType)
            {
                case LabelTypesEnum.Label:
                    g.DrawString(labelItem.LabelText,
                        new Font(labelItem.FontName ?? "Arial", labelItem.FontSize, (labelItem.IsBold ? FontStyle.Bold : FontStyle.Regular) | (labelItem.IsItalic ? FontStyle.Italic : FontStyle.Regular)),
                        Brushes.Black, labelItem.StartX, labelItem.StartY);
                    break;
                case LabelTypesEnum.BarCode:
                    var content = labelItem.LabelText;

                    var writer = new BarcodeWriter
                    {
                        Format = BarcodeFormat.CODE_128,
                        Options = new ZXing.QrCode.QrCodeEncodingOptions
                        {
                            ErrorCorrection = ZXing.QrCode.Internal.ErrorCorrectionLevel.H,
                            Width = settings.BarCodeMaxWidth,
                            Height = settings.BarCodeHeight,
                            PureBarcode = true,
                        }
                    };
                    var barCodeBmp = writer.Write(content);
                    g.DrawImageUnscaled(barCodeBmp, labelItem.StartX, labelItem.StartY);
                    break;
                case LabelTypesEnum.Stamp:
                    var pen = new Pen(Color.Black, 2);
                    g.DrawEllipse(pen, labelItem.StartX, labelItem.StartY, settings.StampDiameter, settings.StampDiameter);
                    g.DrawString(labelItem.LabelText,
                        new Font(labelItem.FontName ?? "Arial", labelItem.FontSize, (labelItem.IsBold ? FontStyle.Bold : FontStyle.Regular) | (labelItem.IsItalic ? FontStyle.Italic : FontStyle.Regular)),
                        Brushes.Black, labelItem.StartX + 2, labelItem.StartY + 11);
                    break;
            }
        }
开发者ID:kurochkin,项目名称:Printing,代码行数:35,代码来源:Form1.cs


注:本文中的ZXing.BarcodeWriter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。