protected BarcodeType GetBarcodeType(JObject jObject) { BarcodeType result = null; bool hasItem = jObject.ContainsKey("TypeName"); if (hasItem) { JToken encodeType = jObject["TypeName"]; if (encodeType != null) { string encodeTypeName = encodeType.Value <string>(); if (!String.IsNullOrEmpty(encodeTypeName)) { foreach (BarcodeType item in BarcodeTypes.AllTypes) { if (item.TypeName == encodeTypeName) { result = item; break; } } } } } return(result); }
public static IFBarcode CreateBarcode(BarcodeType type) { IFBarcode barcode = null; switch (type) { case BarcodeType.Code_39: barcode = m_Code39; break; case BarcodeType.Code_128: barcode = m_Code128; break; case BarcodeType.Code_QR: barcode = m_CodeQR; break; case BarcodeType.Code_QR_Mini: barcode = m_CodeQRMini; break; } return(barcode); }
/* Barcode Commands */ public byte[] PrintBarcode(BarcodeType type, string barcode, BarcodeCode code = BarcodeCode.CODE_B) { DataValidator.ValidateBarcode(type, code, barcode); // For CODE128, prepend the first 2 characters as 0x7B and the CODE type, and escape 0x7B characters. if (type == BarcodeType.CODE128) { if (code == BarcodeCode.CODE_C) { var b = Encoding.ASCII.GetBytes(barcode); var ob = new byte[b.Length / 2]; for (int i = 0, obc = 0; i < b.Length; i += 2) { ob[obc++] = (byte)((b[i] - '0') * 10 + (b[i + 1] - '0')); } barcode = Encoding.ASCII.GetString(ob); } barcode = barcode.Replace("{", "{{"); barcode = $"{(char) 0x7B}{(char) code}" + barcode; } var command = new List <byte> { Cmd.GS, Barcodes.PrintBarcode, (byte)type, (byte)barcode.Length }; command.AddRange(barcode.ToCharArray().Select(x => (byte)x)); return(command.ToArray()); }
public static byte[] GetBarCode(string txt, BarcodeType type, BarcodeTextPosition txtpos) { string path = Application.StartupPath + "\\log.bmp"; string strtxm = txt; FileStream filestr = new FileStream(path, FileMode.Create); Cobainsoft.Windows.Forms.BarcodeControl control = new BarcodeControl(); //实例化 control.BarcodeType = type; //启用的编码 control.Data = strtxm; //生成编码的字符串 control.StretchText = false; control.CopyRight = ""; //显示标题 control.TextPosition = txtpos; //显示位置,Above,NotShown,Below filestr.Close(); //关闭文件 control.SaveImage(ImageFormat.Bmp, 1, 90, true, false, null, path); byte[] imgs = SetImageToByteArray(path); if (System.IO.File.Exists(path)) { try { System.IO.File.Delete(path); } catch { MessageBox.Show("缺少log.bmp文件"); } } return(imgs); }
public override void DetectBarcode(BarcodeType barcodeType, string codeId, string barcode) { if (gunManager.detectBarcode != null) { gunManager.detectBarcode(barcodeType, codeId, barcode); } }
public static int[] GetBarcodeDataValues(string barcodeDataString, BarcodeType codeSet, out byte[] encoded) { if (codeSet == BarcodeType.GS1_128A || codeSet == BarcodeType.GS1_128B) { encoded = new byte[barcodeDataString.Length * 11]; int[] barcodeDataValues = new int[barcodeDataString.Length]; for (int i = 0; i < barcodeDataString.Length; i++) { string character = barcodeDataString[i].ToString(); Code128EncodationEntry entry = codeSet == BarcodeType.GS1_128A ? Entries.First(e => e.A == character) : Entries.First(e => e.B == character); int characterValue = int.Parse(entry.Value); barcodeDataValues[i] = characterValue; entry.Encoded.CopyTo(encoded, i * 11); } return(barcodeDataValues); } else { int[] barcodeDataValues = new int[barcodeDataString.Length / 2]; encoded = new byte[barcodeDataValues.Length * 11]; for (int i = 0, j = 0; i < barcodeDataString.Length; i += 2, j++) { string characterC = barcodeDataString.Substring(i, 2); var entry = Entries.First(e => e.C == characterC); var characterCValue = int.Parse(entry.Value); barcodeDataValues[j] = characterCValue; entry.Encoded.CopyTo(encoded, j * 11); } return(barcodeDataValues); } }
public BarcodeAdjustment(Number input) { String key = GetSpecialBarcodeKey(input.ToString().Substring(0, 2)); switch (key) { case WeightPrefix: this.Quantity = new Number(Decimal.Parse(BarcodeValue(input)) / 1000); this.Type = BarcodeType.ByGramma; break; case QuantityPrefix: this.Quantity = new Number(Int32.Parse(BarcodeValue(input))); this.Type = BarcodeType.ByQuantity; if (Quantity.ToDecimal() > 100) { throw new OutofQuantityLimitException(); } break; case TotalAmountPrefix: this.Amount = Decimal.Parse(BarcodeValue(input)) / 100; this.Type = BarcodeType.ByTotalAmount; break; case PricePrefix: this.Price = Decimal.Parse(BarcodeValue(input)) / 100; this.Type = BarcodeType.ByPrice; break; } }
/// <summary> /// Initializes a new instance of the <see cref="Barcode"/> class. /// </summary> /// <param name="data">The data to encode as a barcode.</param> public Barcode(string data) { _data = data; _type = BarcodeType.Code128; InitializeType(); }
/// <summary> /// Initializes a new instance of the <see cref="Barcode" /> class. /// </summary> /// <param name="data">The data to encode as a barcode.</param> /// <param name="type">The type of barcode. Defaults to Code128</param> public Barcode(string data, BarcodeType type) { _data = data; _type = type; InitializeType(); }
public static BarcodeType FindNewType(string text, int i) { BarcodeType btype = BarcodeType.Code128B; if (text[i] == (char)0xBF) { i++; } string acopy = text.Substring(i); int index = acopy.IndexOf((char)0xBF); if (index >= 0) { acopy = acopy.Substring(0, index); } // Look for 128C if ((acopy.Length % 2) == 0) { btype = BarcodeType.Code128C; foreach (char c in acopy) { if (!StringUtil.IsDigit(c)) { btype = BarcodeType.Code128B; break; } } } return(btype); }
protected void setTitleConvBarcodeThread(object obj, BarcodeType type) { DataGridViewCell cell = (DataGridViewCell)obj; if (cell.ToolTipText == this.tooltip_BarcodeSearching) { return; } bool f = false; try { ControlUtil.SafelyOperated(this, (MethodInvoker) delegate() { cell.ToolTipText = this.tooltip_BarcodeSearching; }); f = this.setTitleConvBarcode_Impl(cell, type); } catch (Exception e) { MessageBox.Show(e.Message, "ISBN/JAN検索"); } finally { if (f == false) { //書名をセットしなかった } ControlUtil.SafelyOperated(this, (MethodInvoker) delegate() { cell.ToolTipText = null; }); } }
public List<BarcodeType> GetAllActiveBarcodeTypes() { List<BarcodeType> barcodeTypes = null; _log.DebugFormat("dbo.GetAllActiveBarcodeTypes"); try { barcodeTypes = new List<BarcodeType>(); DataSet ds = GetDatasetByCommand("dbo.GetAllActiveBarcodeTypes"); DataRowCollection rows = ds.Tables[0].Rows; foreach (DataRow row in rows) { BarcodeType barcodeType = new BarcodeType(); barcodeType.ID = Convert.ToInt64(row["ID"]); barcodeType.Name = Convert.ToString(row["Name"]); barcodeType.Deleted = Convert.ToBoolean(row["Deleted"]); barcodeTypes.Add(barcodeType); } } catch (Exception ex) { _log.ErrorFormat("Exception Occured: Exception={0}", ex); } return barcodeTypes; }
public Barcode(BarcodeType type, string message, string encoding, string alternateText) { Format = type; Message = message; Encoding = encoding; AlternateText = alternateText; }
public Task <Image> EncodeImage(BarcodeType type, string content, int width, int height) { var barcode = new BarcodeLib.Barcode { IncludeLabel = true, Alignment = BarcodeLib.AlignmentPositions.CENTER, RotateFlipType = RotateFlipType.RotateNoneFlipNone, BackColor = Color.White, ForeColor = Color.Black, LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER, AlternateLabel = content }; Image image; if (width < ImagingConstants.MinimalBarcodeWidth || height < ImagingConstants.MinimalBarcodeHeight) { image = barcode.Encode((BarcodeLib.TYPE)((int)type), content); } else { image = barcode.Encode((BarcodeLib.TYPE)((int)type), content, width, height); } return(Task.FromResult(image)); }
public static Settings Create(bool enableBarcodeScanning = true, BarcodeType barcodeType = BarcodeType.All, float qRCodeSize = .1f) => new Settings() { EnableBarcodeScanning = enableBarcodeScanning, ScanTypes = barcodeType, QRCodeSize = qRCodeSize };
public override void DetectBarcode(BarcodeType barcodeType, string codeId, NSData barcodeData) { if (gunManager.detectBarcodeData != null) { gunManager.detectBarcodeData(barcodeType, codeId, barcodeData); } }
public void DisableBarcodeType(BarcodeType type) { if (IsConnected) { scannerInterface.DisableBarcodeType((int)type); } }
private static MediaVisionSource GenerateSource(BarcodeGenerationConfiguration config, string message, BarcodeType type, int qrMode, int qrEcc, int qrVersion) { if (message == null) { throw new ArgumentNullException(nameof(message)); } ValidationUtil.ValidateEnum(typeof(BarcodeType), type); MediaVisionSource source = new MediaVisionSource(); try { InteropBarcode.GenerateSource(EngineConfiguration.GetHandle(config), message, type, qrMode, qrEcc, qrVersion, source.Handle). Validate("Failed to generate source"); } catch (Exception) { source.Dispose(); throw; } return(source); }
}//CheckNumericOnly //private string GetXML() //{ // if (EncodedValue == "") // throw new System.Exception("EGETXML-1: Could not retrieve XML due to the barcode not being encoded first. Please call Encode first."); // else // { // try // { // using (BarcodeXML xml = new BarcodeXML()) // { // BarcodeXML.BarcodeRow row = xml.Barcode.NewBarcodeRow(); // row.Type = EncodedType.ToString(); // row.RawData = RawData; // row.EncodedValue = EncodedValue; // row.EncodingTime = EncodingTime; // row.IncludeLabel = IncludeLabel; // row.Forecolor = ColorTranslator.ToHtml(ForeColor); // row.Backcolor = ColorTranslator.ToHtml(BackColor); // row.CountryAssigningManufacturingCode = Country_Assigning_Manufacturer_Code; // row.ImageWidth = Width; // row.ImageHeight = Height; // row.RotateFlipType = this.RotateFlipType; // row.LabelPosition = this.LabelPosition; // row.LabelFont = this.LabelFont.ToString(); // row.ImageFormat = this.ImageFormat.ToString(); // row.Alignment = this.Alignment; // //get image in base 64 // using (MemoryStream ms = new MemoryStream()) // { // EncodedImage.Save(ms, ImageFormat); // row.Image = Convert.ToBase64String(ms.ToArray(), Base64FormattingOptions.None); // } // xml.Barcode.AddBarcodeRow(row); // StringWriter sw = new StringWriter(); // xml.WriteXml(sw, XmlWriteMode.WriteSchema); // return sw.ToString(); // } // } // catch (System.Exception ex) // { // throw new System.Exception("EGETXML-2: " + ex.Message); // } // } //} //public static Image GetImageFromXML(BarcodeXML internalXML) //{ // try // { // //converting the base64 string to byte array // Byte[] imageContent = new Byte[internalXML.Barcode[0].Image.Length]; // //loading it to memory stream and then to image object // using (MemoryStream ms = new MemoryStream(Convert.FromBase64String(internalXML.Barcode[0].Image))) // { // return Image.FromStream(ms); // } // } // catch (System.Exception ex) // { // throw new System.Exception("EGETIMAGEFROMXML-1: " + ex.Message); // } //} #endregion #region Static Methods /// <summary> /// Encodes the raw data into binary form representing bars and spaces. Also generates an Image of the barcode. /// </summary> /// <param name="iType">Type of encoding to use.</param> /// <param name="Data">Raw data to encode.</param> /// <returns>Image representing the barcode.</returns> public static Image DoEncode(BarcodeType iType, string Data) { using (Barcode b = new Barcode()) { return(b.Encode(iType, Data)); } }
public void EnableBarcodeType(BarcodeType type, bool enableOnlyThis) { if (IsConnected) { scannerInterface.EnableBarcodeType((int)type, enableOnlyThis); } }
private bool IsContentValid(BarcodeType type, string content) { switch (type) { case BarcodeType.UPC_A: case BarcodeType.UPC_E: return((content.Length == 11 || content.Length == 12) && (content.All(i => i >= 48 && i <= 57))); case BarcodeType.EAN13: return((content.Length == 12 || content.Length == 13) && (content.All(i => i >= 48 && i <= 57))); case BarcodeType.EAN8: return((content.Length == 7 || content.Length == 8) && (content.All(i => i >= 48 && i <= 57))); case BarcodeType.CODE39: return(content.All(i => (i >= 45 && i <= 57) || (i >= 65 && i <= 90) || i == 32 || i == 36 || i == 37 || i == 43)); case BarcodeType.I25: return((content.Length % 2 == 0) && (content.All(i => i >= 48 && i <= 57))); case BarcodeType.CODEBAR: return(content.All(i => (i >= 45 && i <= 58) || (i >= 65 && i <= 68) || i == 36 || i == 43)); case BarcodeType.CODE93: case BarcodeType.CODE128: return(content.All(i => i >= 0 && i <= 127)); case BarcodeType.CODE11: case BarcodeType.MSI: return(content.All(i => i >= 48 && i <= 57)); } return(false); }
/// <summary> /// 画一维条码 /// </summary> /// <param name="type">条码类型</param> /// <param name="x">条码起始x坐标</param> /// <param name="y">条码起始y坐标</param> /// <param name="text">条码内容</param> /// <param name="lineWidth">条码线条宽度</param> /// <param name="height">条码高度</param> /// <param name="ratio">宽条与窄条的比率</param> /// <param name="rotation">旋转角度</param> public CPCLPrintCommand DrawBarcode1D(BarcodeType type, int x, int y, string text, int lineWidth, int height, int ratio, RotationAngle rotation) { if (!string.IsNullOrWhiteSpace(text)) { DrawBarcode1D(Helper.ConvertBarcodeType(type), x, y, text, lineWidth, height, ratio, (int)rotation); } return(this); }
public void EventBarcodeData(NSData barcodeData, BarcodeType barcodeType, int scannerID) { if (barcodeData == null) { throw new ArgumentNullException("barcodeData"); } global::ApiDefinitions.ZebraMessaging.void_objc_msgSend_IntPtr_int_int(this.Handle, Selector.GetHandle("sbtEventBarcodeData:barcodeType:fromScanner:"), barcodeData.Handle, (int)barcodeType, scannerID); }
public GateOrderTicketAgentData(ICompositeKey <GateTicket> gateTicketKey, string number, string barcode, BarcodeType barcodeType) { Number = number; Barcode = barcode; BarcodeType = barcodeType; GateTicketKey = gateTicketKey; }
public async Task <string> EncodeBase64(BarcodeType type, string content, int width, int height) { var image = await this.EncodeImage(type, content, width, height); var result = image.ToBase64String(ImageFormat.Bmp); return(result); }
public async Task <byte[]> Encode(BarcodeType type, string content, int width, int height) { var image = await this.EncodeImage(type, content, width, height); var result = image.ToByteArray(ImageFormat.Bmp); return(result); }
public void AddBarCode(string message, BarcodeType type, string encoding) { Barcode = new BarCode(); Barcode.Type = type; Barcode.Message = message; Barcode.Encoding = encoding; Barcode.AlternateText = null; }
/// <summary> /// Encodes the raw data into binary form representing bars and spaces. Also generates an Image of the barcode. /// </summary> /// <param name="iType">Type of encoding to use.</param> /// <param name="Data">Raw data to encode.</param> /// <param name="IncludeLabel">Include the label at the bottom of the image with data encoded.</param> /// <param name="DrawColor">Foreground color</param> /// <param name="BackColor">Background color</param> /// <param name="Width">Width of the resulting barcode.(pixels)</param> /// <param name="Height">Height of the resulting barcode.(pixels)</param> /// <returns>Image representing the barcode.</returns> public static Image DoEncode(BarcodeType iType, string Data, bool IncludeLabel, Color DrawColor, Color BackColor, int Width, int Height) { using (Barcode b = new Barcode()) { b.IncludeLabel = IncludeLabel; return(b.Encode(iType, Data, DrawColor, BackColor, Width, Height)); } }
/// <summary> /// Encodes the raw data into binary form representing bars and spaces. Also generates an Image of the barcode. /// </summary> /// <param name="iType">Type of encoding to use.</param> /// <param name="Data">Raw data to encode.</param> /// <param name="IncludeLabel">Include the label at the bottom of the image with data encoded.</param> /// <returns>Image representing the barcode.</returns> public static Image DoEncode(BarcodeType iType, string Data, bool IncludeLabel) { using (Barcode b = new Barcode()) { b.IncludeLabel = IncludeLabel; return(b.Encode(iType, Data)); } }
/// <summary> /// Печать штрихового кода /// </summary> /// <param name="barcodeValue">Данные ШК</param> /// <param name="barcodeType">Тип ШК</param> public PrintBarcodeOperation(string barcodeValue, BarcodeType barcodeType) : base("PrintBarCode") { if (barcodeValue.IsNullOrEmptyOrWhiteSpace()) { throw new ArgumentException( string.Format( ErrorStrings.ResourceManager.GetString("StringFormatError"), this.GetType().GetProperty(nameof(Value)).GetDisplayName()), nameof(barcodeValue)); } var isBarcodeValueValid = false; switch (barcodeType) { case BarcodeType.EAN8: if (Regex.IsMatch(barcodeValue, RegexHelper.BarcodeEAN8Pattern)) { isBarcodeValueValid = true; } break; case BarcodeType.EAN13: if (Regex.IsMatch(barcodeValue, RegexHelper.BarcodeEAN13Pattern)) { isBarcodeValueValid = true; } break; case BarcodeType.CODE39: if (Regex.IsMatch(barcodeValue, RegexHelper.BarcodeCODE39Pattern)) { isBarcodeValueValid = true; } break; case BarcodeType.QR: if (barcodeValue.Length < 256) { isBarcodeValueValid = true; } break; } if (!isBarcodeValueValid) { throw new ArgumentException( string.Format(ErrorStrings.ResourceManager.GetString("BarcodeValueFormatError"), barcodeType.GetDisplayName()), nameof(barcodeValue)); } BcType = barcodeType; Value = barcodeValue; }
/// <summary> /// A method to locate a mask for a barcode. Takes the barcode line entered. Variable "found" is true if found, else false. /// </summary> /// <param name="barcodeId">The barcode as it was entered or scanned.</param> internal void Find(string barcodeId) { timeStarted = DateTime.Now; found = false; string barcodePrefix = barcodeId.Substring(0, 1) + "%"; string queryString = "SELECT LEN(PREFIX) AS LENGTH,* FROM RETAILBARCODEMASKTABLE WHERE PREFIX LIKE @PREFIX AND DATAAREAID = @DATAAREAID ORDER BY LENGTH DESC,MASK"; try { using (SqlCommand command = new SqlCommand(queryString, connection)) { SqlParameter prefixParm = command.Parameters.Add("@PREFIX", SqlDbType.NVarChar, 22); prefixParm.Value = barcodePrefix; SqlParameter dataAreaIdParm = command.Parameters.Add("@DATAAREAID", SqlDbType.NVarChar, 4); dataAreaIdParm.Value = DATAAREAID; if (connection.State == ConnectionState.Closed) { connection.Open(); } SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { string readPrefix = reader.GetString(reader.GetOrdinal("PREFIX")); if (barcodeId.Length >= readPrefix.Length) { barcodePrefix = barcodeId.Substring(0, readPrefix.Length); if (readPrefix == barcodePrefix) { description = reader.GetString(reader.GetOrdinal("DESCRIPTION")); mask = reader.GetString(reader.GetOrdinal("MASK")); prefix = reader.GetString(reader.GetOrdinal("PREFIX")); maskId = reader.GetString(reader.GetOrdinal("MASKID")); symbology = (BarcodeType)reader.GetInt32(reader.GetOrdinal("SYMBOLOGY")); internalType = (BarcodeInternalType)reader.GetInt32(reader.GetOrdinal("TYPE")); timeFinished = DateTime.Now; timeElapsed = timeFinished - timeStarted; if (barcodeId.Length == mask.Length) { found = true; break; } } } } } } finally { if (connection.State == ConnectionState.Open) { connection.Close(); } } }
/// <summary> /// Calculates the check digit for a 1D UPC or EAN barcode. /// </summary> /// <param name="barcode">The barcode without the check digit as a string.</param> /// <param name="type">The type of the barcode (can be UPC-A, UPC-E, EAN-8 or EAN-13).</param> /// <returns>The check digit as an integer.</returns> public static int CalculateCheckDigit(string barcode, BarcodeType type) { int checkDigit; int oddSum = 0; int evenSum = 0; for (int i = 0; i < barcode.Length; i++) { int number = Convert.ToInt16(Char.GetNumericValue(barcode[i])); if ((i + 1) % 2 == 0) evenSum += number; else oddSum += number; } switch (type) { case BarcodeType.UPCA: if (barcode.Length != 11) { checkDigit = (int)ErrorCodes.Errors.InvalidBarcodeLength; break; } checkDigit = ((oddSum * 3) + evenSum) % 10; checkDigit = checkDigit != 0 ? 10 - checkDigit : checkDigit; break; case BarcodeType.EAN13: if (barcode.Length != 12) { checkDigit = (int)ErrorCodes.Errors.InvalidBarcodeLength; break; } checkDigit = ((evenSum * 3) + oddSum) % 10; checkDigit = checkDigit != 0 ? 10 - checkDigit : checkDigit; break; case BarcodeType.EAN8: if (barcode.Length != 7) { checkDigit = (int)ErrorCodes.Errors.InvalidBarcodeLength; break; } checkDigit = ((oddSum * 3) + evenSum) % 10; checkDigit = checkDigit != 0 ? 10 - checkDigit : checkDigit; break; default: checkDigit = (int)ErrorCodes.Errors.UnknownError; break; } return checkDigit; }
public async Task<Product[]> Search(string barcode, BarcodeType barcodeType) { var searchCriteria = new SearchCriteria { Operation = "ItemLookup", SearchIndex = "Grocery", ResponseGroups = new[] { "Images", "ItemAttributes" }, IdType = barcodeType.ToString(), ItemId = barcode }; var items = await _client.GetItems(searchCriteria); return items.Select(i => _factory.Create(i, searchCriteria)).ToArray(); }
public static Bitmap GenerateBarcode(string Data , BarcodeType type) { switch (type) { case BarcodeType.DATAMATRIX: return DataMatrix(Data); case BarcodeType.PDF417: return PDF417(Data); case BarcodeType.QRCODE: return Qrcode(Data); default : return PDF417(Data); } }
public List<string> ScanBitmap(WriteableBitmap bmp, int numscans, ScanDirection direction, BarcodeType types) { List<string> result = new List<string>(); Parser parser = new Parser(); int height = direction == ScanDirection.Horizontal ? bmp.PixelWidth : bmp.PixelHeight; if (numscans > height) numscans = height; // fix for doing full scan on small images for (int i = 0; i < numscans; i++) { int y1 = (i * height) / numscans; int y2 = ((i + 1) * height) / numscans; string codesRead = parser.ReadBarcodes(bmp, y1, y2, direction, types); if (!string.IsNullOrEmpty(codesRead)) { result.AddRange(codesRead.Split('|')); } } return result; }
/// <summary> /// Scans the active frame in the passed bitmap for barcodes. /// </summary> /// <param name="CodesRead">Will contain detected barcode strings when the function returns</param> /// <param name="bmp">Input bitmap</param> /// <param name="numscans">Number of passes that must be made over the page. /// 50 - 100 usually gives a good result.</param> /// <param name="direction">Scan direction</param> /// <param name="types">Barcode types. Pass BarcodeType.All, or you can specify a list of types, /// e.g., BarcodeType.Code39 | BarcodeType.EAN</param> public static void ScanPage(ref System.Collections.ArrayList CodesRead, Bitmap bmp, int numscans, ScanDirection direction, BarcodeType types) { int iHeight, iWidth; if (direction == ScanDirection.Horizontal) { iHeight = bmp.Width; iWidth = bmp.Height; } else { iHeight = bmp.Height; iWidth = bmp.Width; } if (numscans > iHeight) numscans = iHeight; // fix for doing full scan on small images for (int i = 0; i < numscans; i++) { int y1 = (i * iHeight) / numscans; int y2 = ((i + 1) * iHeight) / numscans; string sCodesRead = ReadBarcodes(bmp, y1, y2, direction, types); if ((sCodesRead != null) && (sCodesRead.Length > 0)) { string[] asCodes = sCodesRead.Split('|'); foreach (string sCode in asCodes) { if (!CodesRead.Contains(sCode)) CodesRead.Add(sCode); } } } }
/// <summary> /// Scans one band in the passed bitmap for barcodes. /// </summary> /// <param name="bmp">Input bitmap</param> /// <param name="start">Start coordinate</param> /// <param name="end">End coordinate</param> /// <param name="direction"> /// ScanDirection.Vertical: a horizontal band across the page will be examined /// and start,end should be valid y-coordinates. /// ScanDirection.Horizontal: a vertical band across the page will be examined /// and start,end should be valid x-coordinates. /// </param> /// <param name="types">Barcode types to be found</param> /// <returns>Pipe-separated list of barcodes, empty string if none were detected</returns> public static string ReadBarcodes(Bitmap bmp, int start, int end, ScanDirection direction, BarcodeType types) { string sBarCodes = "|"; // will hold return values // To find a horizontal barcode, find the vertical histogram to find individual barcodes, // then get the vertical histogram to decode each histogramResult vertHist = verticalHistogram(bmp, start, end, direction); // Get the light/dark bar patterns. // GetBarPatterns returns the bar pattern in 2 formats: // // sbCode39Pattern: for Code39 (only distinguishes narrow bars "n" and wide bars "w") // sbEANPattern: for EAN (distinguishes bar widths 1, 2, 3, 4 and L/G-code) // StringBuilder sbCode39Pattern; StringBuilder sbEANPattern; GetBarPatterns(ref vertHist, out sbCode39Pattern, out sbEANPattern); // We now have a barcode in terms of narrow & wide bars... Parse it! if ((sbCode39Pattern.Length > 0) || (sbEANPattern.Length > 0)) { for (int iPass = 0; iPass < 2; iPass++) { if ((types & BarcodeType.Code39) != BarcodeType.None) // if caller wanted Code39 { string sCode39 = ParseCode39(sbCode39Pattern); if (sCode39.Length > 0) sBarCodes += sCode39 + "|"; } if ((types & BarcodeType.EAN) != BarcodeType.None) // if caller wanted EAN { string sEAN = ParseEAN(sbEANPattern); if (sEAN.Length > 0) sBarCodes += sEAN + "|"; } if ((types & BarcodeType.Code128) != BarcodeType.None) // if caller wanted Code128 { // Note: Code128 uses same bar width measurement data as EAN string sCode128 = ParseCode128(sbEANPattern); if (sCode128.Length > 0) sBarCodes += sCode128 + "|"; } // Reverse the bar pattern arrays to read again in the mirror direction if (iPass == 0) { sbCode39Pattern = ReversePattern(sbCode39Pattern); sbEANPattern = ReversePattern(sbEANPattern); } } } // Return pipe-separated list of found barcodes, if any if (sBarCodes.Length > 2) return sBarCodes.Substring(1, sBarCodes.Length - 2); return string.Empty; }
/// <summary> /// Inicializa uma nova instancia da classe <see cref="BarcodeAdapter"/>. /// </summary> /// <param name="type">Tipo do barcode.</param> internal BarcodeAdapter(BarcodeType type) { _type = type; ResolveBarcodeType(); }
/// <summary> /// Converts between UPC and EAN barcodes. /// </summary> /// <param name="sourceBarcode">The source barcode as a string.</param> /// <param name="sourceType">The type of the source barcode.</param> /// <param name="targetType">The type the barcode should be converted to.</param> /// <returns>The barcode as a string, null if the specified conversion isn't valid.</returns> public static string ConvertBarcode(string sourceBarcode, BarcodeType sourceType, BarcodeType targetType) { /* Define valid barcode conversions */ Dictionary<BarcodeType, List<BarcodeType>> validConversions = new Dictionary<BarcodeType, List<BarcodeType>>(); validConversions.Add(BarcodeType.EAN8, new List<BarcodeType>()); validConversions.Add(BarcodeType.EAN13, new List<BarcodeType> { BarcodeType.UPCA, BarcodeType.UPCE }); /* This is only possible if the first digit of the EAN-13 is '0' */ validConversions.Add(BarcodeType.UPCA, new List<BarcodeType> { BarcodeType.EAN13, BarcodeType.UPCE }); validConversions.Add(BarcodeType.UPCE, new List<BarcodeType> { BarcodeType.UPCA, BarcodeType.EAN13 }); if (validConversions[sourceType].Contains(targetType)) /* Conversion is valid */ { switch (sourceType) { case BarcodeType.EAN13: switch (targetType) { case BarcodeType.UPCA: if (sourceBarcode.Substring(0, 1) == "0") return sourceBarcode.Substring(1); else return null; case BarcodeType.UPCE: string converted = ConvertBarcode(sourceBarcode, BarcodeType.EAN13, BarcodeType.UPCA); if (converted != null) return ConvertBarcode(converted, BarcodeType.UPCA, BarcodeType.UPCE); else return null; default: return null; } case BarcodeType.UPCA: switch (targetType) { case BarcodeType.EAN13: return "0" + sourceBarcode; case BarcodeType.UPCE: if ((sourceBarcode.Substring(3, 3) == "000") || (sourceBarcode.Substring(3, 3) == "100") || (sourceBarcode.Substring(3, 3) == "200")) return sourceBarcode.Substring(1, 2) + sourceBarcode.Substring(8, 3) + sourceBarcode.Substring(3, 1) + sourceBarcode.Substring(sourceBarcode.Length - 1); else if (sourceBarcode.Substring(4, 2) == "00") return sourceBarcode.Substring(1, 3) + sourceBarcode.Substring(9, 2) + "3" + sourceBarcode.Substring(sourceBarcode.Length - 1); else if (sourceBarcode.Substring(5, 1) == "0") return sourceBarcode.Substring(1, 4) + sourceBarcode.Substring(10, 1) + "4" + sourceBarcode.Substring(sourceBarcode.Length - 1); else if (Convert.ToInt16(sourceBarcode.Substring(10, 1)) >= 5) return sourceBarcode.Substring(1, 5) + sourceBarcode.Substring(10, 1) + sourceBarcode.Substring(sourceBarcode.Length - 1); else return null; default: return null; } case BarcodeType.UPCE: switch (targetType) { case BarcodeType.UPCA: if (Convert.ToInt16(sourceBarcode.Substring(5, 1)) >= 0 && Convert.ToInt16(sourceBarcode.Substring(5, 1)) <= 2) return "0" + sourceBarcode.Substring(0, 2) + sourceBarcode.Substring(5, 1) + "0000" + sourceBarcode.Substring(2, 3) + sourceBarcode.Substring(sourceBarcode.Length - 1); else if (sourceBarcode.Substring(5, 1) == "3") return "0" + sourceBarcode.Substring(0, 3) + "00000" + sourceBarcode.Substring(3, 2) + sourceBarcode.Substring(sourceBarcode.Length - 1); else if (sourceBarcode.Substring(5, 1) == "4") return "0" + sourceBarcode.Substring(0, 4) + "00000" + sourceBarcode.Substring(4, 1) + sourceBarcode.Substring(sourceBarcode.Length - 1); else if (Convert.ToInt16(sourceBarcode.Substring(5, 1)) >= 5) return "0" + sourceBarcode.Substring(0, 5) + "0000" + sourceBarcode.Substring(sourceBarcode.Length - 2); else return null; case BarcodeType.EAN13: return ConvertBarcode(ConvertBarcode(sourceBarcode, BarcodeType.UPCE, BarcodeType.UPCA), BarcodeType.UPCA, BarcodeType.EAN13); default: return null; } default: return null; } } else /* Invalid conversion attempted */ return null; }
/// <summary> /// Checks the check digit of a given barcode. /// </summary> /// <param name="barcode">The barcode as a string.</param> /// <param name="type">The type of the barcode (can be UPC-A, UPC-E, EAN-8 or EAN-13).</param> /// <returns>True if the check digit is correct, false otherwise.</returns> public static bool CheckBarcode(string barcode, BarcodeType type) { return (barcode.Substring(0, barcode.Length - 1) + CalculateCheckDigit(barcode.Substring(0, barcode.Length - 1), type) == barcode); }
public Barcode(BarcodeType barcodeType) { BarcodeType = barcodeType; }
/// <summary> /// Prints the barcode data. /// </summary> /// <param name='type'> /// Type of barcode. /// </param> /// <param name='data'> /// Data to print. /// </param> public void PrintBarcode(BarcodeType type, string data) { byte[] originalBytes; byte[] outputBytes; if (type == BarcodeType.code93 || type == BarcodeType.code128) { originalBytes = System.Text.Encoding.UTF8.GetBytes(data); outputBytes = originalBytes; } else { originalBytes = System.Text.Encoding.UTF8.GetBytes(data.ToUpper()); //outputBytes = System.Text.Encoding.Convert(System.Text.Encoding.UTF8,System.Text.Encoding.GetEncoding(this.Encoding),originalBytes); outputBytes = originalBytes; } switch (type) { case BarcodeType.upc_a: if (data.Length == 11 || data.Length == 12) { _writeByte(29); _writeByte(107); _writeByte(0); _serialPort.Write(outputBytes,0,data.Length); _writeByte(0); } break; case BarcodeType.upc_e: if (data.Length == 11 || data.Length == 12) { _writeByte(29); _writeByte(107); _writeByte(1); _serialPort.Write(outputBytes,0,data.Length); _writeByte(0); } break; case BarcodeType.ean13: if (data.Length == 12 || data.Length == 13) { _writeByte(29); _writeByte(107); _writeByte(2); _serialPort.Write(outputBytes,0,data.Length); _writeByte(0); } break; case BarcodeType.ean8: if (data.Length == 7 || data.Length == 8) { _writeByte(29); _writeByte(107); _writeByte(3); _serialPort.Write(outputBytes,0,data.Length); _writeByte(0); } break; case BarcodeType.code39: if (data.Length > 1) { _writeByte(29); _writeByte(107); _writeByte(4); _serialPort.Write(outputBytes,0,data.Length); _writeByte(0); } break; case BarcodeType.i25: if (data.Length > 1 || data.Length % 2 == 0) { _writeByte(29); _writeByte(107); _writeByte(5); _serialPort.Write(outputBytes,0,data.Length); _writeByte(0); } break; case BarcodeType.codebar: if (data.Length > 1) { _writeByte(29); _writeByte(107); _writeByte(6); _serialPort.Write(outputBytes,0,data.Length); _writeByte(0); } break; case BarcodeType.code93: //todo: overload PrintBarcode method with a byte array parameter if (data.Length > 1) { _writeByte(29); _writeByte(107); _writeByte(7); //todo: use format 2 (init string : 29,107,72) (0x00 can be a value, too) _serialPort.Write(outputBytes,0,data.Length); _writeByte(0); } break; case BarcodeType.code128: //todo: overload PrintBarcode method with a byte array parameter if (data.Length > 1) { _writeByte(29); _writeByte(107); _writeByte(8); //todo: use format 2 (init string : 29,107,73) (0x00 can be a value, too) _serialPort.Write(outputBytes,0,data.Length); _writeByte(0); } break; case BarcodeType.code11: if (data.Length > 1) { _writeByte(29); _writeByte(107); _writeByte(9); _serialPort.Write(outputBytes,0,data.Length); _writeByte(0); } break; case BarcodeType.msi: if (data.Length > 1) { _writeByte(29); _writeByte(107); _writeByte(10); _serialPort.Write(outputBytes,0,data.Length); _writeByte(0); } break; } }
public LabelBarcodeGenerator SetBarcodeType(BarcodeType type) { _barcodeType = type; return this; }
internal Barcode(NativeBarcode native) : base(native) { BarcodeType = native.BarcodeType.FromNative(); }
public static extern IntPtr imaqReadBarcode(IntPtr image, BarcodeType type, ref ROI roi, int validate);
/// <summary> /// Creates a barcode of the specified type in the specified file. /// </summary> public void Generate(string Data, BarcodeType Format, string FileName) { switch(Format) { case BarcodeType.Code39: GenerateCode39(Data,FileName); break; case BarcodeType.Code39Extended: GenerateCode39Extended(Data,FileName); break; } }
/// <summary> /// Outputs a barcode of the specified type to a Stream object. /// </summary> public void Generate(string Data, BarcodeType Format, Stream OutputStream) { switch(Format) { case BarcodeType.Code39: GenerateCode39(Data,OutputStream); break; case BarcodeType.Code39Extended: GenerateCode39Extended(Data,OutputStream); break; } }
public void AddBarCode(string message, BarcodeType type, string encoding) { Barcode = new BarCode() { Type = type, Message = message, Encoding = encoding, AlternateText = null }; }
public static bool SetConfig(BarcodeType barcode_type, BarcodeCase barcode_case) { return WMS_SetConfig((ulong)barcode_type, (byte)barcode_case); }