/// <summary> /// </summary> /// <param name="contents">The contents to encode in the barcode</param> /// <param name="format">The barcode format to generate</param> /// <param name="width">The preferred width in pixels</param> /// <param name="height">The preferred height in pixels</param> /// <param name="hints">Additional parameters to supply to the encoder</param> /// <returns> /// The generated barcode as a Matrix of unsigned bytes (0 == black, 255 == white) /// </returns> public BitMatrix encode(String contents, BarcodeFormat format, int width, int height, IDictionary<EncodeHintType, object> hints) { Encoding charset = DEFAULT_CHARSET; int? eccPercent = null; if (hints != null) { if (hints.ContainsKey(EncodeHintType.CHARACTER_SET)) { object charsetname = hints[EncodeHintType.CHARACTER_SET]; if (charsetname != null) { charset = Encoding.GetEncoding(charsetname.ToString()); } } if (hints.ContainsKey(EncodeHintType.ERROR_CORRECTION)) { object eccPercentObject = hints[EncodeHintType.ERROR_CORRECTION]; if (eccPercentObject != null) { eccPercent = Convert.ToInt32(eccPercentObject); } } } return encode(contents, format, charset, eccPercent == null ? Internal.Encoder.DEFAULT_EC_PERCENT : eccPercent.Value); }
public ByteMatrix encode(String contents, BarcodeFormat format, int width, int height,Hashtable hints) { if (contents == null || contents.Length == 0) { throw new ArgumentException("Found empty contents"); } if (format != BarcodeFormat.QR_CODE) { throw new ArgumentException("Can only encode QR_CODE, but got " + format); } if (width < 0 || height < 0) { throw new ArgumentException("Requested dimensions are too small: " + width + 'x' + height); } ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel.L; if (hints != null) { ErrorCorrectionLevel requestedECLevel = (ErrorCorrectionLevel) hints[EncodeHintType.ERROR_CORRECTION]; if (requestedECLevel != null) { errorCorrectionLevel = requestedECLevel; } } QRCode code = new QRCode(); Encoder.encode(contents, errorCorrectionLevel, code); return renderResult(code, width, height); }
/// <summary> /// Encode the contents following specified format. /// {@code width} and {@code height} are required size. This method may return bigger size /// {@code BitMatrix} when specified size is too small. The user can set both {@code width} and /// {@code height} to zero to get minimum size barcode. If negative value is set to {@code width} /// or {@code height}, {@code IllegalArgumentException} is thrown. /// </summary> public virtual BitMatrix encode(String contents, BarcodeFormat format, int width, int height, IDictionary<EncodeHintType, object> hints) { if (contents.Length == 0) { throw new ArgumentException("Found empty contents"); } if (width < 0 || height < 0) { throw new ArgumentException("Negative size is not allowed. Input: " + width + 'x' + height); } int sidesMargin = DefaultMargin; if (hints != null) { var sidesMarginInt = hints.ContainsKey(EncodeHintType.MARGIN) ? (int)hints[EncodeHintType.MARGIN] : (int?)null; if (sidesMarginInt != null) { sidesMargin = sidesMarginInt.Value; } } var code = encode(contents); return renderResult(code, width, height, sidesMargin); }
public BitMatrix encode(String contents, BarcodeFormat format, int width, int height, IDictionary<EncodeHintType, object> hints) { if (!formatMap.ContainsKey(format)) throw new ArgumentException("No encoder available for format " + format); return formatMap[format]().encode(contents, format, width, height, hints); }
/// <summary> /// /// </summary> /// <param name="contents"></param> /// <param name="format"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="hints"></param> /// <returns></returns> public ByteMatrix encode(System.String contents, BarcodeFormat format, int width, int height, System.Collections.Hashtable hints) { if (contents == null || contents.Length == 0) { throw new System.ArgumentException("Found empty contents"); } if (format != BarcodeFormat.MICRO_QR_CODE) { throw new System.ArgumentException("Can only encode QR_CODE, but got " + format); } if (width < 0 || height < 0) { throw new System.ArgumentException("Requested dimensions are too small: " + width + 'x' + height); } ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel.L; int cVersionNum = -1; if (hints != null) { ErrorCorrectionLevel requestedECLevel = (ErrorCorrectionLevel)hints[EncodeHintType.ERROR_CORRECTION]; if (requestedECLevel != null) { errorCorrectionLevel = requestedECLevel; } int versionNum = (int)hints[EncodeHintType.MICROQRCODE_VERSION]; if (versionNum >= 1 && versionNum <= 4) cVersionNum = versionNum; } MicroQRCode code = new MicroQRCode(); Encoder.encode(contents, errorCorrectionLevel, hints, code, cVersionNum); return renderResult(code, width, height); }
/// <summary> /// </summary> /// <param name="contents">The contents to encode in the barcode</param> /// <param name="format">The barcode format to generate</param> /// <param name="width">The preferred width in pixels</param> /// <param name="height">The preferred height in pixels</param> /// <param name="hints">Additional parameters to supply to the encoder</param> /// <returns> /// The generated barcode as a Matrix of unsigned bytes (0 == black, 255 == white) /// </returns> public BitMatrix encode(String contents, BarcodeFormat format, int width, int height, IDictionary<EncodeHintType, object> hints) { if (format != BarcodeFormat.PDF_417) { throw new ArgumentException("Can only encode PDF_417, but got " + format); } var encoder = new Internal.PDF417(); if (hints != null) { if (hints.ContainsKey(EncodeHintType.PDF417_COMPACT)) { encoder.setCompact((Boolean) hints[EncodeHintType.PDF417_COMPACT]); } if (hints.ContainsKey(EncodeHintType.PDF417_COMPACTION)) { encoder.setCompaction((Compaction) hints[EncodeHintType.PDF417_COMPACTION]); } if (hints.ContainsKey(EncodeHintType.PDF417_DIMENSIONS)) { Dimensions dimensions = (Dimensions) hints[EncodeHintType.PDF417_DIMENSIONS]; encoder.setDimensions(dimensions.MaxCols, dimensions.MinCols, dimensions.MaxRows, dimensions.MinRows); } } return bitMatrixFromEncoder(encoder, contents, width, height); }
public ByteMatrix encode(System.String contents, BarcodeFormat format, int width, int height, System.Collections.Generic.Dictionary<Object,Object> hints) { if (contents == null || contents.Length == 0) { throw new System.ArgumentException("Found empty contents"); } if (format != BarcodeFormat.QR_CODE) { throw new System.ArgumentException("Can only encode QR_CODE, but got " + format); } if (width < 0 || height < 0) { throw new System.ArgumentException("Requested dimensions are too small: " + width + 'x' + height); } ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel.L; if (hints != null && hints.ContainsKey(EncodeHintType.ERROR_CORRECTION)) { errorCorrectionLevel = (ErrorCorrectionLevel)hints[EncodeHintType.ERROR_CORRECTION]; //UPGRADE: Fixed dictionary key grab issue } QRCode code = new QRCode(); Encoder.encode(contents, errorCorrectionLevel, hints, code); return renderResult(code, width, height); }
public override Bitmap Render(BitMatrix matrix, BarcodeFormat format, string content, EncodingOptions options) { int width = matrix.Width; int height = matrix.Height; var backgroundBrush = new LinearGradientBrush( new Rectangle(0, 0, width, height), BackgroundGradientColor, Background, LinearGradientMode.Vertical); var foregroundBrush = new LinearGradientBrush( new Rectangle(0, 0, width, height), ForegroundGradientColor, Foreground, LinearGradientMode.ForwardDiagonal); var bmp = new Bitmap(width, height); var gg = Graphics.FromImage(bmp); gg.Clear(Background); for (int x = 0; x < width - 1; x++) { for (int y = 0; y < height - 1; y++) { if (matrix[x, y]) { gg.FillRectangle(foregroundBrush, x, y, 1, 1); } else { gg.FillRectangle(backgroundBrush, x, y, 1, 1); } } } return bmp; }
/// <summary> /// Initializes a new instance of the <see cref="Result"/> class. /// </summary> /// <param name="text">The text.</param> /// <param name="rawBytes">The raw bytes.</param> /// <param name="resultPoints">The result points.</param> /// <param name="format">The format.</param> public Result(String text, [System.Runtime.InteropServices.WindowsRuntime.ReadOnlyArray] byte[] rawBytes, [System.Runtime.InteropServices.WindowsRuntime.ReadOnlyArray] ResultPoint[] resultPoints, BarcodeFormat format) : this(text, rawBytes, resultPoints, format, DateTime.Now.Ticks) { }
/// <summary> /// Initializes a new instance of the <see cref="Result"/> class. /// </summary> /// <param name="text">The text.</param> /// <param name="rawBytes">The raw bytes.</param> /// <param name="resultPoints">The result points.</param> /// <param name="format">The format.</param> public Result(String text, byte[] rawBytes, ResultPoint[] resultPoints, BarcodeFormat format) : this(text, rawBytes, resultPoints, format, DateTime.Now.Ticks) { }
public ByteMatrix encode(String contents, BarcodeFormat format, int width, int height) { try{ return encode(contents, format, width, height, null); }catch(Exception e){ throw new WriterException(e.Message); } }
/// <summary> /// Returns the zxing reader class for the current specified ScanMode. /// </summary> /// <returns></returns> internal static BarcodeReader GetReader(BarcodeFormat format = BarcodeFormat.All_1D) { return new BarcodeReader() { AutoRotate = true, Options = new ZXing.Common.DecodingOptions() { TryHarder = false, PossibleFormats = new BarcodeFormat[] { format } } }; }
private const int codeWidth = 3 + (7 * 4) + 5 + (7 * 4) + 3; // end guard #endregion Fields #region Methods public override ByteMatrix encode(System.String contents, BarcodeFormat format, int width, int height, System.Collections.Generic.Dictionary <Object,Object> hints) { if (format != BarcodeFormat.EAN_8) { throw new System.ArgumentException("Can only encode EAN_8, but got " + format); } return base.encode(contents, format, width, height, hints); }
private static void doTest(String contents, String normalized, BarcodeFormat format) { ZXing.Result fakeResult = new ZXing.Result(contents, null, null, format); ParsedResult result = ResultParser.parseResult(fakeResult); Assert.AreEqual(ParsedResultType.PRODUCT, result.Type); ProductParsedResult productResult = (ProductParsedResult)result; Assert.AreEqual(contents, productResult.ProductID); Assert.AreEqual(normalized, productResult.NormalizedProductID); }
public BitMatrix encode(String contents, BarcodeFormat format, int width, int height, IDictionary<EncodeHintType, object> hints) { if (String.IsNullOrEmpty(contents)) { throw new ArgumentException("Found empty contents", contents); } if (format != BarcodeFormat.DATA_MATRIX) { throw new ArgumentException("Can only encode DATA_MATRIX, but got " + format); } if (width < 0 || height < 0) { throw new ArgumentException("Requested dimensions are too small: " + width + 'x' + height); } // Try to get force shape & min / max size SymbolShapeHint shape = SymbolShapeHint.FORCE_NONE; Dimension minSize = null; Dimension maxSize = null; if (hints != null) { var requestedShape = hints.ContainsKey(EncodeHintType.DATA_MATRIX_SHAPE) ? (SymbolShapeHint?)hints[EncodeHintType.DATA_MATRIX_SHAPE] : null; if (requestedShape != null) { shape = requestedShape.Value; } var requestedMinSize = hints.ContainsKey(EncodeHintType.MIN_SIZE) ? (Dimension)hints[EncodeHintType.MIN_SIZE] : null; if (requestedMinSize != null) { minSize = requestedMinSize; } var requestedMaxSize = hints.ContainsKey(EncodeHintType.MAX_SIZE) ? (Dimension)hints[EncodeHintType.MAX_SIZE] : null; if (requestedMaxSize != null) { maxSize = requestedMaxSize; } } //1. step: Data encodation String encoded = HighLevelEncoder.encodeHighLevel(contents, shape, minSize, maxSize); SymbolInfo symbolInfo = SymbolInfo.lookup(encoded.Length, shape, minSize, maxSize, true); //2. step: ECC generation String codewords = ErrorCorrection.encodeECC200(encoded, symbolInfo); //3. step: Module placement in Matrix var placement = new DefaultPlacement(codewords, symbolInfo.getSymbolDataWidth(), symbolInfo.getSymbolDataHeight()); placement.place(); //4. step: low-level encoding return encodeLowLevel(placement, symbolInfo); }
private const int codeWidth = 3 + (7 * 6) + 5 + (7 * 6) + 3; // end guard public override ByteMatrix Encode(System.String contents, BarcodeFormat format, int width, int height, System.Collections.Hashtable hints) { if (format != BarcodeFormat.EAN_13) { throw new System.ArgumentException("Can only encode EAN_13, but got " + format); } return base.Encode(contents, format, width, height, hints); }
private const int codeWidth = 3 + (7*6) + 5 + (7*6) + 3; // end guard public override ByteMatrix encode(String contents, BarcodeFormat format, int width, int height, Dictionary<EncodeHintType, Object> hints) { if (format != BarcodeFormat.EAN_13) { throw new ArgumentException("Can only encode EAN_13, but got " + format); } return base.encode(contents, format, width, height, hints); }
/// <summary> /// </summary> /// <param name="contents">The contents to encode in the barcode</param> /// <param name="format">The barcode format to generate</param> /// <param name="width">The preferred width in pixels</param> /// <param name="height">The preferred height in pixels</param> /// <param name="hints">Additional parameters to supply to the encoder</param> /// <returns> /// The generated barcode as a Matrix of unsigned bytes (0 == black, 255 == white) /// </returns> public BitMatrix encode(String contents, BarcodeFormat format, int width, int height, IDictionary<EncodeHintType, object> hints) { if (format != BarcodeFormat.UPC_A) { throw new ArgumentException("Can only encode UPC-A, but got " + format); } return subWriter.encode(preencode(contents), BarcodeFormat.EAN_13, width, height, hints); }
/// <summary> /// Encode the contents following specified format. /// {@code width} and {@code height} are required size. This method may return bigger size /// {@code BitMatrix} when specified size is too small. The user can set both {@code width} and /// {@code height} to zero to get minimum size barcode. If negative value is set to {@code width} /// or {@code height}, {@code IllegalArgumentException} is thrown. /// </summary> /// <param name="contents"></param> /// <param name="format"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="hints"></param> /// <returns></returns> public override BitMatrix encode(String contents, BarcodeFormat format, int width, int height, IDictionary<EncodeHintType, object> hints) { if (format != BarcodeFormat.PLESSEY) { throw new ArgumentException("Can only encode Plessey, but got " + format); } return base.encode(contents, format, width, height, hints); }
public Result(String text, sbyte[] rawBytes, ResultPoint[] resultPoints, BarcodeFormat format) { if (text == null && rawBytes == null) { throw new ArgumentException("Text and bytes are null"); } this.text = text; this.rawBytes = rawBytes; this.resultPoints = resultPoints; this.format = format; resultMetadata = null; }
public static void AssertUITestBackdoorResult(this Xamarin.UITest.IApp app, BarcodeFormat format, string value) { // First wait for the result app.WaitForElement(q => q.Marked("Barcode Result"), "Barcode not scanned, no result found", TimeSpan.FromSeconds(10)); app.TakeScreenshot("Scan Result Found"); var result = app.Query(q => q.Marked(format + "|" + value)); Assert.AreEqual(1, result.Count()); app.Tap(q => q.Marked("OK")); }
/// <summary> /// 文本转条码图片 /// </summary> /// <param name="text">转为条码的文本</param> /// <param name="width">宽度</param> /// <param name="height">高度</param> /// <param name="barcodeFormat">条码格式,默认用:EAN_13</param> /// <returns></returns> public static Bitmap TextToBarCodeImg(string text, int width, int height, BarcodeFormat barcodeFormat = BarcodeFormat.EAN_13) { return(new BarcodeWriter() { Format = barcodeFormat, Options = new EncodingOptions() { Width = width, Height = height, Margin = 2 } }.Write(text)); }
/// <summary> /// Initializes a new instance of the <see cref="Result"/> class. /// </summary> /// <param name="text">The text.</param> /// <param name="rawBytes">The raw bytes.</param> /// <param name="resultPoints">The result points.</param> /// <param name="format">The format.</param> /// <param name="timestamp">The timestamp.</param> public Result(String text, byte[] rawBytes, ResultPoint[] resultPoints, BarcodeFormat format, long timestamp) { if (text == null && rawBytes == null) { throw new ArgumentException("Text and bytes are null"); } Text = text; RawBytes = rawBytes; ResultPoints = resultPoints; BarcodeFormat = format; ResultMetadata = null; Timestamp = timestamp; }
/// <summary> /// </summary> /// <param name="contents">The contents to encode in the barcode</param> /// <param name="format">The barcode format to generate</param> /// <param name="width">The preferred width in pixels</param> /// <param name="height">The preferred height in pixels</param> /// <param name="hints">Additional parameters to supply to the encoder</param> /// <returns> /// The generated barcode as a Matrix of unsigned bytes (0 == black, 255 == white) /// </returns> public BitMatrix encode(String contents, BarcodeFormat format, int width, int height, IDictionary <EncodeHintType, object> hints) { if (format != BarcodeFormat.UPC_A) { throw new ArgumentException("Can only encode UPC-A, but got " + format); } // Transform a UPC-A code into the equivalent EAN-13 code and write it that way return(subWriter.encode('0' + contents, BarcodeFormat.EAN_13, width, height, hints)); }
public MultiFormatReader(BarcodeFormat format) { if (format == BarcodeFormat.EAN_13 || format == BarcodeFormat.EAN_8 || format == BarcodeFormat.CODE_128) { Reader = new MultiFormatOneDReader(format); } else if (format == BarcodeFormat.QR_CODE) { Reader = new QRCodeReader(); } }
private static Color32[] Encode(string textForEncoding, int width, int height, BarcodeFormat format = BarcodeFormat.QR_CODE, int margin = 2) { var writer = new BarcodeWriter { Format = format, Options = new QrCodeEncodingOptions { Height = height, Width = width } }; writer.Options.Margin = margin; return(writer.Write(textForEncoding)); }
public void GoToQRScanner(bool callback = false) { var data = new Bundle(); var barcodeFormats = new BarcodeFormat[] { BarcodeFormat.QrCode }.Cast <int>().ToArray(); data.PutIntArray(Constants.BarcodeFormats, barcodeFormats); data.PutBoolean(Constants.Callback, callback); GoTo <BarcodeQRScanner>(data); }
6; // end guard public override BitMatrix encode(String contents, BarcodeFormat format, int width, int height, IDictionary <EncodeHintType, object> hints) { if (format != BarcodeFormat.UPC_E) { throw new ArgumentException("Can only encode UPC_E, but got " + format); } return(base.encode(contents, format, width, height, hints)); }
/// <summary> /// 获取文件路径 /// </summary> /// <param name="fileCategory"></param> /// <param name="content"></param> /// <param name="format"></param> /// <returns></returns> private static string GetFilePath(string fileCategory, string content, BarcodeFormat format) { var now = DateTime.Now; var filePath = $"{AppDomain.CurrentDomain.BaseDirectory}Zxing\\{fileCategory}\\{now.Year}\\{now.Month}\\{format.ToString()}"; if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } filePath += $"\\{content}.jpg"; return(filePath); }
protected async Task <Result> Scanning(BarcodeFormat barcodeFormat) { var options = new MobileBarcodeScanningOptions(); options.PossibleFormats = new List <ZXing.BarcodeFormat>() { barcodeFormat }; var scanner = new MobileBarcodeScanner(); return(await scanner.Scan(options)); }
public override BitMatrix encode(String contents, BarcodeFormat format, int width, int height, IDictionary hints) { if (format != BarcodeFormat.ITF) { throw new ArgumentException("Can only encode ITF, but got " + format); } return(base.encode(contents, format, width, height, hints)); }
/// <summary> /// Initializes a new instance of the <see cref="Result"/> class. /// </summary> /// <param name="text">The text.</param> /// <param name="rawBytes">The raw bytes.</param> /// <param name="resultPoints">The result points.</param> /// <param name="format">The format.</param> /// <param name="timestamp">The timestamp.</param> public Result(String text, byte[] rawBytes, ResultPoint[] resultPoints, BarcodeFormat format, long timestamp) { if (text == null && rawBytes == null) { throw new ArgumentException("Text and bytes are null"); } Text = text; RawBytes = rawBytes; ResultPoints = resultPoints; BarcodeFormat = format; ResultMetadata = null; Timestamp = timestamp; }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public com.google.zxing.common.BitMatrix encode(String contents, com.google.zxing.BarcodeFormat format, int width, int height, java.util.Map<com.google.zxing.EncodeHintType,?> hints) throws com.google.zxing.WriterException public BitMatrix encode(string contents, BarcodeFormat format, int width, int height, IDictionary <EncodeHintType, object> hints) { if (contents.Length == 0) { throw new System.ArgumentException("Found empty contents"); } if (format != BarcodeFormat.QR_CODE) { throw new System.ArgumentException("Can only encode QR_CODE, but got " + format); } if (width < 0 || height < 0) { throw new System.ArgumentException("Requested dimensions are too small: " + width + 'x' + height); } ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel.L; int quietZone = QUIET_ZONE_SIZE; if (hints != null) { //ErrorCorrectionLevel requestedECLevel = (ErrorCorrectionLevel) hints[EncodeHintType.ERROR_CORRECTION]; ErrorCorrectionLevel requestedECLevel = null; if (hints.ContainsKey(EncodeHintType.ERROR_CORRECTION)) { requestedECLevel = (ErrorCorrectionLevel)hints[EncodeHintType.ERROR_CORRECTION]; } if (requestedECLevel != null) { errorCorrectionLevel = requestedECLevel; } //int? quietZoneInt = (int?) hints[EncodeHintType.MARGIN]; int?quietZoneInt = null; if (hints.ContainsKey(EncodeHintType.MARGIN)) { quietZoneInt = (int?)hints[EncodeHintType.MARGIN]; } if (quietZoneInt != null) { quietZone = (int)quietZoneInt; } } QRCode code = Encoder.encode(contents, errorCorrectionLevel, hints); return(renderResult(code, width, height, quietZone)); }
/// <summary> /// Initializes a new instance of the <see cref="Result"/> class. /// </summary> /// <param name="text">The text.</param> /// <param name="rawBytes">The raw bytes.</param> /// <param name="numBits"></param> /// <param name="resultPoints">The result points.</param> /// <param name="format">The format.</param> /// <param name="timestamp">The timestamp.</param> public Result(String text, [System.Runtime.InteropServices.WindowsRuntime.ReadOnlyArray] byte[] rawBytes, int numBits, [System.Runtime.InteropServices.WindowsRuntime.ReadOnlyArray] ResultPoint[] resultPoints, BarcodeFormat format, long timestamp) { if (text == null && rawBytes == null) { throw new ArgumentException("Text and bytes are null"); } Text = text; RawBytes = rawBytes; NumBits = numBits; ResultPoints = resultPoints; BarcodeFormat = format; ResultMetadata = null; Timestamp = timestamp; }
public override void ParseCode(Document doc, BarcodeFormat format, string codeText) { switch (format) { case BarcodeFormat.CODE_39: ParseCode39 (doc, codeText); break; case BarcodeFormat.EAN_13: ParseCode13 (doc, codeText); break; default: logger.Error ("Нет правил разбора для штрих-кода {0}.", format); break; } }
/// <summary> /// 生成二维码,返回位图 /// </summary> /// <param name="input">输入的需要编码的信息字符串</param> /// <param name="fromat">二维码格式</param> /// <param name="CanvasWidth">画布宽度</param> /// <param name="CanvasHeight">画布高度</param> /// <param name="imageFormat">图像格式</param> /// <param name="logoImageFileName">中间嵌入的 Logo 图片</param> /// <returns></returns> public static Bitmap CreateCode(string input, BarcodeFormat fromat, int CanvasWidth, int CanvasHeight, System.Drawing.Imaging.ImageFormat imageFormat, string logoImageFileName) { System.Collections.Hashtable hints = new System.Collections.Hashtable(); hints.Add(EncodeHintType.CHARACTER_SET, "utf-8"); ByteMatrix byteMatrix = new MultiFormatWriter().encode(input, fromat, CanvasWidth, CanvasHeight, hints); int x, y; int width = byteMatrix.Width; int height = byteMatrix.Height; Bitmap bmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); for (x = 0; x < width; x++) { for (y = 0; y < height; y++) { bmap.SetPixel(x, y, byteMatrix.get_Renamed(x, y) != -1 ? ColorTranslator.FromHtml("0xFF000000") : ColorTranslator.FromHtml("0xFFFFFFFF")); } } if (String.IsNullOrEmpty(logoImageFileName.Trim()) || (!System.IO.File.Exists(logoImageFileName))) { return(bmap); } // 加图片水印 System.Drawing.Image logo = System.Drawing.Image.FromFile(logoImageFileName); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmap); // 设置高质量插值法 g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; // 设置高质量,低速度呈现平滑程度 g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; // 清空画布并以透明背景色填充 //g.Clear(System.Drawing.Color.Transparent); // 计算 Logo 的范围 x = (width - logo.Width) / 2; y = (height - logo.Height) / 2; //在指定位置并且按指定大小绘制原图片的指定部分 g.DrawImage(logo, new System.Drawing.Rectangle(x, y, logo.Width, logo.Height), 0, 0, logo.Width, logo.Height, System.Drawing.GraphicsUnit.Pixel); logo.Dispose(); g.Dispose(); return(bmap); }
public Result Decode(FileInfo file, BarcodeFormat format, KeyValuePair <DecodeHintType, object>[] aditionalHints = null) { MultiFormatReader r = GetReader(format, aditionalHints); BinaryBitmap image = GetImage(file); if (image is null) { return(null); } Result result = r.decode(image); return(result); }
/// <summary> /// Creates barcode /// </summary> /// <param name="content">Content string</param> /// <param name="bf">Barcode Format</param> /// <param name="width">width (standard value 100)</param> /// <param name="height">height (standard value 100)</param> /// <param name="margin">Margin (standard value 0)</param> /// <returns></returns> public static Bitmap CreateBarcode(string content, BarcodeFormat bf = BarcodeFormat.QR_CODE, int width = 100, int height = 100, int margin = 0) { var barcodeWriter = new BarcodeWriter { Options = new EncodingOptions { Width = width, Height = height, Margin = margin, PureBarcode = true }, Format = bf }; return(barcodeWriter.Write(barcodeWriter.Encode(content))); }
private BitmapImage GenerateBarcodeImage(string barcodeContent, BarcodeFormat barcodeType) { var barcodeWriter = new ZXing.Presentation.BarcodeWriter(); barcodeWriter.Format = barcodeType; barcodeWriter.Options = new EncodingOptions { Width = BARCODE_WIDTH, Height = BARCODE_HEIGHT }; var bc = barcodeWriter.Write(barcodeContent); return(ToBitMapImage(bc)); }
public virtual ByteMatrix Encode(System.String contents, BarcodeFormat format, int width, int height, System.Collections.Hashtable hints) { if (contents == null || contents.Length == 0) { throw new System.ArgumentException("Found empty contents"); } if (width < 0 || height < 0) { throw new System.ArgumentException("Requested dimensions are too small: " + width + 'x' + height); } sbyte[] code = encode(contents); return renderResult(code, width, height); }
public MultiFormatOneDReader(BarcodeFormat format) { if (format == BarcodeFormat.EAN_8) { Reader = new EAN8Reader(); } else if (format == BarcodeFormat.EAN_13) { Reader = new EAN13Reader(); } else if (format == BarcodeFormat.CODE_128) { Reader = new Code128Reader(); } }
public virtual ByteMatrix Encode(System.String contents, BarcodeFormat format, int width, int height, System.Collections.Hashtable hints) { if (contents == null || contents.Length == 0) { throw new System.ArgumentException("Found empty contents"); } if (width < 0 || height < 0) { throw new System.ArgumentException("Requested dimensions are too small: " + width + 'x' + height); } sbyte[] code = encode(contents); return(renderResult(code, width, height)); }
/// <summary> /// 生成二维码 /// </summary> /// <param name="content"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="margin"></param> /// <param name="format"></param> /// <param name="logoFilStream"></param> public static void GenerateQrCode(string content, int width = 200, int height = 200, int margin = 1, BarcodeFormat format = BarcodeFormat.QR_CODE, Stream logoFilStream = null) { var img = GenerateBitmap(content, width, height, margin, format); var filePath = GetFilePath("QRCode", content, format); SetLogoImgage(img, logoFilStream); img.Save(filePath, ImageFormat.Jpeg); }
public async Task ShareBarcodeAsync(string text, BarcodeFormat format) { var bytes = GetBarcodeBytes(text, format); var fileName = $"{DateTime.Now.ToString("yyyyMMddHHmmss")}_{format}.png"; var file = Path.Combine(FileSystem.CacheDirectory, fileName); File.WriteAllBytes(file, bytes); await Share.RequestAsync(new ShareFileRequest { Title = fileName, File = new ShareFile(file) }); }
/// <summary> /// Starts the scan : navigates to the scan page and starts reading video stream /// Note : Scan will auto-stop if navigation occurs /// </summary> /// <param name="onBarCodeFound">Delegate Action on a barcode found</param> /// <param name="onError">Delegate Action on error</param> /// <param name="zxingReader">(optional) A specific reader format, Default will be EAN13Reader </param> public static void StartScan(Action<string> onBarCodeFound, Action<Exception> onError, TimeSpan? maxTry = null, BarcodeFormat barcodeFormat = BarcodeFormat.EAN_13) { if(maxTry.HasValue) { MaxTry = maxTry.Value; } OnBarCodeFound = onBarCodeFound; OnError = onError; _ZXingReader = GetReader(barcodeFormat); _rootFrame = Window.Current.Content as Frame; _rootFrame.Navigate(typeof(BarcodePage)); }
private static void doTestResult(String contents, String goldenResult, ParsedResultType type, BarcodeFormat format) { ZXing.Result fakeResult = new ZXing.Result(contents, null, null, format); ParsedResult result = ResultParser.parseResult(fakeResult); Assert.IsNotNull(result); Assert.AreEqual(type, result.Type); String displayResult = result.DisplayResult; Assert.AreEqual(goldenResult, displayResult); }
static BarcodeReader CreateBarcodeReader(BarcodeFormat barcodeFormat, bool autoRotate, bool tryInverted, bool tryHarder) { return(new BarcodeReader { AutoRotate = autoRotate, TryInverted = tryInverted, Options = { TryHarder = tryHarder, PossibleFormats = new List <BarcodeFormat> { barcodeFormat } } }); }
public Bitmap createBarcode(String barcodeText, BarcodeFormat barcodeFormat, int width, int height) { if (!string.IsNullOrEmpty(barcodeText)) { try { ByteMatrix bt = barcodeWriter.Encode(barcodeText, barcodeFormat, width, height); return(ConvertByteMatrixToImage(bt)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } return(null); }
public virtual ByteMatrix encode(String contents, BarcodeFormat format, int width, int height, Dictionary<EncodeHintType, Object> hints) { if (contents == null || contents.Length == 0) { throw new ArgumentException("Found empty contents"); } if (width < 0 || height < 0) { throw new ArgumentException("Requested dimensions are too small: " + width + 'x' + height); } sbyte[] code = encode(contents); return renderResult(code, width, height); }
public Bitmap createBarcode(String barcodeText, BarcodeFormat barcodeFormat, int width, int height) { if (!string.IsNullOrEmpty(barcodeText)) { try { ByteMatrix bt = barcodeWriter.Encode(barcodeText, barcodeFormat, width, height); return ConvertByteMatrixToImage(bt); } catch (Exception ex) { MessageBox.Show(ex.Message); } } return null; }
/// <summary> /// 生成二维码,返回位图 /// </summary> /// <param name="input">输入的需要编码的信息字符串</param> /// <param name="fromat">二维码格式</param> /// <param name="canvasWidth">画布宽度</param> /// <param name="canvasHeight">画布高度</param> /// <param name="imageFormat">图像格式</param> /// <param name="logoImageFileName">中间嵌入的 Logo 图片</param> /// <returns></returns> public static Bitmap CreateCode(string input, BarcodeFormat fromat, int canvasWidth, int canvasHeight, System.Drawing.Imaging.ImageFormat imageFormat, string logoImageFileName) { var barcodeWriter = new BarcodeWriter <Bitmap> { Format = fromat, Options = new EncodingOptions { Height = canvasHeight, Width = canvasWidth, Margin = 0 } }; barcodeWriter.Options.Hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8"); barcodeWriter.Options.Hints.Add(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); var bmap = barcodeWriter.Write(input); if (string.IsNullOrEmpty(logoImageFileName.Trim()) || (!System.IO.File.Exists(logoImageFileName))) { return(bmap); } // 加图片水印 System.Drawing.Image logo = System.Drawing.Image.FromFile(logoImageFileName); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmap); // 设置高质量插值法 g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; // 设置高质量,低速度呈现平滑程度 g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; // 清空画布并以透明背景色填充 //g.Clear(System.Drawing.Color.Transparent); // 计算 Logo 的范围 int x = (canvasWidth - logo.Width) / 2; int y = (canvasHeight - logo.Height) / 2; //在指定位置并且按指定大小绘制原图片的指定部分 g.DrawImage(logo, new System.Drawing.Rectangle(x, y, logo.Width, logo.Height), 0, 0, logo.Width, logo.Height, System.Drawing.GraphicsUnit.Pixel); logo.Dispose(); g.Dispose(); return(bmap); }
/// <summary> /// Converts this ByteMatrix to a black and white bitmap. /// </summary> /// <returns>A black and white bitmap converted from this ByteMatrix.</returns> public Bitmap ToBitmap(BarcodeFormat format, String content) { int width = Width; int height = Height; bool outputContent = !(content == null || content.Length == 0) && (format == BarcodeFormat.CODE_39 || format == BarcodeFormat.CODE_128 || format == BarcodeFormat.EAN_13 || format == BarcodeFormat.EAN_8 || format == BarcodeFormat.CODABAR || format == BarcodeFormat.ITF || format == BarcodeFormat.UPC_A); int emptyArea = outputContent ? 16 : 0; // create the bitmap and lock the bits because we need the stride // which is the width of the image and possible padding bytes var bmp = new Bitmap(width, height); for (int y = 0; y < height - emptyArea; y++) { for (var x = 0; x < width; x++) { var color = this[x, y] ? Color.Black : Color.White; bmp.SetPixel(x, y, color); } } if (outputContent) { //switch (format) //{ // case BarcodeFormat.EAN_8: // if (content.Length < 8) // content = OneDimensionalCodeWriter.CalculateChecksumDigitModulo10(content); // content = content.Insert(4, " "); // break; // case BarcodeFormat.EAN_13: // if (content.Length < 13) // content = OneDimensionalCodeWriter.CalculateChecksumDigitModulo10(content); // content = content.Insert(7, " "); // content = content.Insert(1, " "); // break; //} bmp.DrawText(content, null, Color.Black, width / 2, height - 14); } return(bmp); }
/// <summary> /// Encode the contents following specified format. /// {@code width} and {@code height} are required size. This method may return bigger size /// {@code BitMatrix} when specified size is too small. The user can set both {@code width} and /// {@code height} to zero to get minimum size barcode. If negative value is set to {@code width} /// or {@code height}, {@code IllegalArgumentException} is thrown. /// </summary> public virtual BitMatrix Encode(string contents, BarcodeFormat format, int width, int height, Mode mode = null, int quietZone = 4, IDictionary <EncodeHintType, object> hints = null) { if (string.IsNullOrEmpty(contents)) { throw new ArgumentException("Found empty contents"); } if (width < 0 || height < 0) { throw new ArgumentException("Negative size is not allowed. Input: " + width + 'x' + height); } var supportedFormats = SupportedWriteFormats; if (supportedFormats != null && !supportedFormats.Contains(format)) { #if NET20 || NET35 var supportedFormatsArray = new string[supportedFormats.Count]; for (var i = 0; i < supportedFormats.Count; i++) { supportedFormatsArray[i] = supportedFormats[i].ToString(); } throw new ArgumentException("Can only encode " + string.Join(", ", supportedFormatsArray) + ", but got " + format); #else throw new ArgumentException("Can only encode " + string.Join(", ", supportedFormats) + ", but got " + format); #endif } int sidesMargin = DefaultMargin; if (hints != null) { var sidesMarginInt = hints.ContainsKey(EncodeHintType.MARGIN) ? hints[EncodeHintType.MARGIN] : null; if (sidesMarginInt != null) { sidesMargin = Convert.ToInt32(sidesMarginInt); } } var code = Encode(contents); return(RenderResult(code, width, height, sidesMargin)); }
/// <summary> /// Initializes a new instance of the <see cref="Result"/> class. /// </summary> /// <param name="text">The text.</param> /// <param name="rawBytes">The raw bytes.</param> /// <param name="resultPoints">The result points.</param> /// <param name="format">The format.</param> /// <param name="timestamp">The timestamp.</param> public Result(String text, [System.Runtime.InteropServices.WindowsRuntime.ReadOnlyArray] byte[] rawBytes, [System.Runtime.InteropServices.WindowsRuntime.ReadOnlyArray] ResultPoint[] resultPoints, BarcodeFormat format, long timestamp) { if (text == null && rawBytes == null) { throw new ArgumentException("Text and bytes are null"); } Text = text; RawBytes = rawBytes; ResultPoints = resultPoints; BarcodeFormat = format; ResultMetadata = null; Timestamp = timestamp; }
/// <summary> /// Converts this ByteMatrix to a black and white bitmap. /// </summary> /// <returns>A black and white bitmap converted from this ByteMatrix.</returns> public Bitmap ToBitmap(BarcodeFormat format, String content) { int width = Width; int height = Height; bool outputContent = !(content == null || content.Length == 0) && (format == BarcodeFormat.CODE_39 || format == BarcodeFormat.CODE_128 || format == BarcodeFormat.EAN_13 || format == BarcodeFormat.EAN_8 || format == BarcodeFormat.CODABAR || format == BarcodeFormat.ITF || format == BarcodeFormat.UPC_A); int emptyArea = outputContent ? 16 : 0; // create the bitmap and lock the bits because we need the stride // which is the width of the image and possible padding bytes var bmp = new Bitmap(width, height); for (int y = 0; y < height - emptyArea; y++) { for (var x = 0; x < width; x++) { var color = this[x, y] ? Color.Black : Color.White; bmp.SetPixel(x, y, color); } } if (outputContent) { //switch (format) //{ // case BarcodeFormat.EAN_8: // if (content.Length < 8) // content = OneDimensionalCodeWriter.CalculateChecksumDigitModulo10(content); // content = content.Insert(4, " "); // break; // case BarcodeFormat.EAN_13: // if (content.Length < 13) // content = OneDimensionalCodeWriter.CalculateChecksumDigitModulo10(content); // content = content.Insert(7, " "); // content = content.Insert(1, " "); // break; //} bmp.DrawText(content, null, Color.Black, width / 2, height - 14); } return bmp; }
private void Create(SvgImage image, BitMatrix matrix, BarcodeFormat format, string content, EncodingOptions options) { const int quietZone = 5; if (matrix == null) { return; } int width = matrix.Width; int height = matrix.Height; image.AddHeader(); image.AddTag(0, 0, 2 * quietZone + width, 2 * quietZone + height, Background, Foreground); AppendDarkCell(image, matrix, quietZone, quietZone); image.AddEnd(); }
private void Create(SvgImage image, BitMatrix matrix, BarcodeFormat format, string content, EncodingOptions options) { if (matrix == null) { return; } const int spaceBetweenMatrixAndText = 3; int width = matrix.Width; int height = matrix.Height; var outputContent = (options == null || !options.PureBarcode) && !String.IsNullOrEmpty(content) && (format == BarcodeFormat.CODE_39 || format == BarcodeFormat.CODE_93 || format == BarcodeFormat.CODE_128 || format == BarcodeFormat.EAN_13 || format == BarcodeFormat.EAN_8 || format == BarcodeFormat.CODABAR || format == BarcodeFormat.ITF || format == BarcodeFormat.UPC_A || format == BarcodeFormat.UPC_E || format == BarcodeFormat.MSI || format == BarcodeFormat.PLESSEY); if (outputContent) { var fontSize = FontSize < 1 ? DefaultFontSize : FontSize; height += fontSize + spaceBetweenMatrixAndText; } image.AddHeader(); image.AddTag(0, 0, width, height, Background, Foreground); AppendDarkCell(image, matrix, 0, 0); if (outputContent) { var fontName = String.IsNullOrEmpty(FontName) ? DefaultFontName : FontName; var fontSize = FontSize < 1 ? DefaultFontSize : FontSize; content = ModifyContentDependingOnBarcodeFormat(format, content); image.AddText(content, fontName, fontSize); } image.AddEnd(); }
public override BitMatrix encode(String contents, BarcodeFormat format, int width, int height, IDictionary<EncodeHintType, object> hints) { if (format != BarcodeFormat.CODE_128) { throw new ArgumentException("Can only encode CODE_128, but got " + format); } forceCodesetB = (hints != null && hints.ContainsKey(EncodeHintType.CODE128_FORCE_CODESET_B) && (bool) hints[EncodeHintType.CODE128_FORCE_CODESET_B]); return base.encode(contents, format, width, height, hints); }
public override BitMatrix encode(String contents, BarcodeFormat format, int width, int height, IDictionary <EncodeHintType, object> hints) { if (format != BarcodeFormat.CODE_128) { throw new ArgumentException("Can only encode CODE_128, but got " + format); } forceCodesetB = (hints != null && hints.ContainsKey(EncodeHintType.CODE128_FORCE_CODESET_B) && (bool)hints[EncodeHintType.CODE128_FORCE_CODESET_B]); return(base.encode(contents, format, width, height, hints)); }
public override void ViewDidLoad () { this.Root = new RootElement("Zxing.Net Demo") { new Section("Barcode Reading"), new Section("Barcode Writing") }; var readers = new BarcodeFormat[] { BarcodeFormat.AZTEC, BarcodeFormat.CODABAR, BarcodeFormat.CODE_128, BarcodeFormat.CODE_39, BarcodeFormat.CODE_93, BarcodeFormat.DATA_MATRIX, BarcodeFormat.EAN_13, BarcodeFormat.EAN_8, BarcodeFormat.ITF, BarcodeFormat.MAXICODE, BarcodeFormat.PDF_417, BarcodeFormat.QR_CODE, BarcodeFormat.RSS_14, BarcodeFormat.RSS_EXPANDED, BarcodeFormat.UPC_A, BarcodeFormat.UPC_E, BarcodeFormat.UPC_EAN_EXTENSION }; foreach (var fmt in readers) { this.Root[0].Add(new StyledStringElement(fmt.ToString(), () => { decoderViewController = new DecoderViewController("Read: " + fmt.ToString(), fmt); this.NavigationController.PushViewController(decoderViewController, true); }) { Accessory = UITableViewCellAccessory.DisclosureIndicator }); } var writers = new BarcodeFormat[] { BarcodeFormat.UPC_A, BarcodeFormat.EAN_8, BarcodeFormat.EAN_13, BarcodeFormat.CODE_39, BarcodeFormat.CODE_128, BarcodeFormat.ITF, BarcodeFormat.CODABAR, BarcodeFormat.QR_CODE, BarcodeFormat.PDF_417 }; foreach (var fmt in writers) { this.Root[1].Add(new StyledStringElement(fmt.ToString(), () => { encoderViewController = new EncoderViewController("Write: " + fmt.ToString(), fmt); this.NavigationController.PushViewController(encoderViewController, true); }) { Accessory = UITableViewCellAccessory.DisclosureIndicator }); } }