/// <summary> /// Implementation of the GetOldBarcodeImage() method for IBarCodeGenerator interface. /// </summary> /// <param name="parameters"></param> /// <returns></returns> public Image GetOldBarcodeImage(BarcodeParameters parameters) { if (parameters.PostalAddress == null) { return(null); } BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.Postnet) { CodeText = parameters.PostalAddress }; // Hardcode type for old-fashioned Barcode #if NET462 || JAVA return(generator.GenerateBarCodeImage()); #elif NETCOREAPP2_1 || __MOBILE__ generator.GenerateBarCodeImage().Save(ArtifactsDir + "OldBarcodeImage.png"); return(Image.Decode(ArtifactsDir + "OldBarcodeImage.png")); #endif }
/// <summary> /// Implementation of the GetBarCodeImage() method for IBarCodeGenerator interface. /// </summary> /// <param name="parameters"></param> /// <returns></returns> public Image GetBarcodeImage(BarcodeParameters parameters) { if (parameters.BarcodeType == null || parameters.BarcodeValue == null) { return(null); } BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.QR); string type = parameters.BarcodeType.ToUpper(); switch (type) { case "QR": generator = new BarcodeGenerator(EncodeTypes.QR); break; case "CODE128": generator = new BarcodeGenerator(EncodeTypes.Code128); break; case "CODE39": generator = new BarcodeGenerator(EncodeTypes.Code39Standard); break; case "EAN8": generator = new BarcodeGenerator(EncodeTypes.EAN8); break; case "EAN13": generator = new BarcodeGenerator(EncodeTypes.EAN13); break; case "UPCA": generator = new BarcodeGenerator(EncodeTypes.UPCA); break; case "UPCE": generator = new BarcodeGenerator(EncodeTypes.UPCE); break; case "ITF14": generator = new BarcodeGenerator(EncodeTypes.ITF14); break; case "CASE": generator = new BarcodeGenerator(EncodeTypes.None); break; } if (generator.BarcodeType.Equals(EncodeTypes.None)) { return(null); } generator.CodeText = parameters.BarcodeValue; if (generator.BarcodeType.Equals(EncodeTypes.QR)) { generator.Parameters.Barcode.CodeTextParameters.TwoDDisplayText = parameters.BarcodeValue; } if (parameters.ForegroundColor != null) { generator.Parameters.Barcode.BarColor = ConvertColor(parameters.ForegroundColor); } if (parameters.BackgroundColor != null) { generator.Parameters.BackColor = ConvertColor(parameters.BackgroundColor); } if (parameters.SymbolHeight != null) { generator.Parameters.ImageHeight.Pixels = ConvertSymbolHeight(parameters.SymbolHeight); generator.Parameters.AutoSizeMode = AutoSizeMode.None; } generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.None; if (parameters.DisplayText) { generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below; } generator.Parameters.CaptionAbove.Text = ""; const float scale = 2.4f; // Empiric scaling factor for converting Word barcode to Aspose.BarCode float xdim = 1.0f; if (generator.BarcodeType.Equals(EncodeTypes.QR)) { generator.Parameters.AutoSizeMode = AutoSizeMode.Nearest; generator.Parameters.ImageWidth.Inches *= scale; generator.Parameters.ImageHeight.Inches = generator.Parameters.ImageWidth.Inches; xdim = generator.Parameters.ImageHeight.Inches / 25; generator.Parameters.Barcode.XDimension.Inches = generator.Parameters.Barcode.BarHeight.Inches = xdim; } if (parameters.ScalingFactor != null) { float scalingFactor = ConvertScalingFactor(parameters.ScalingFactor); generator.Parameters.ImageHeight.Inches *= scalingFactor; if (generator.BarcodeType.Equals(EncodeTypes.QR)) { generator.Parameters.ImageWidth.Inches = generator.Parameters.ImageHeight.Inches; generator.Parameters.Barcode.XDimension.Inches = generator.Parameters.Barcode.BarHeight.Inches = xdim * scalingFactor; } generator.Parameters.AutoSizeMode = AutoSizeMode.None; } #if NET462 || JAVA return(generator.GenerateBarCodeImage()); #elif NETCOREAPP2_1 || __MOBILE__ generator.GenerateBarCodeImage().Save(ArtifactsDir + "GetBarcodeImage.png"); return(Image.Decode(ArtifactsDir + "GetBarcodeImage.png")); #endif }