/// <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 NET48 || JAVA
            return generator.GenerateBarCodeImage();
            #elif NET5_0 || __MOBILE__
            generator.GenerateBarCodeImage().Save(ArtifactsDir + "OldBarcodeImage.png");
            return Image.Decode(ArtifactsDir + "OldBarcodeImage.png");
            #endif
        }
示例#2
0
        /// <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);
            }

            BarCodeBuilder builder = new BarCodeBuilder
            {
                EncodeType = Aspose.BarCode.Generation.EncodeTypes.Postnet,
                CodeText   = parameters.PostalAddress
            };

            // Hardcode type for old-fashioned Barcode
#if NET462 || JAVA
            return(builder.BarCodeImage);
#elif NETCOREAPP2_1 || __MOBILE__
            builder.BarCodeImage.Save(ApiExampleBase.ArtifactsDir + "OldBarcodeImage.png");
            return(Image.Decode(ApiExampleBase.ArtifactsDir + "OldBarcodeImage.png"));
#endif
        }
示例#3
0
        /// <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);
            }

            BarCodeBuilder builder = new BarCodeBuilder();

            string type = parameters.BarcodeType.ToUpper();

            switch (type)
            {
            case "QR":
                builder.EncodeType = Aspose.BarCode.Generation.EncodeTypes.QR;
                break;

            case "CODE128":
                builder.EncodeType = Aspose.BarCode.Generation.EncodeTypes.Code128;
                break;

            case "CODE39":
                builder.EncodeType = Aspose.BarCode.Generation.EncodeTypes.Code39Standard;
                break;

            case "EAN8":
                builder.EncodeType = Aspose.BarCode.Generation.EncodeTypes.EAN8;
                break;

            case "EAN13":
                builder.EncodeType = Aspose.BarCode.Generation.EncodeTypes.EAN13;
                break;

            case "UPCA":
                builder.EncodeType = Aspose.BarCode.Generation.EncodeTypes.UPCA;
                break;

            case "UPCE":
                builder.EncodeType = Aspose.BarCode.Generation.EncodeTypes.UPCE;
                break;

            case "ITF14":
                builder.EncodeType = Aspose.BarCode.Generation.EncodeTypes.ITF14;
                break;

            case "CASE":
                builder.EncodeType = Aspose.BarCode.Generation.EncodeTypes.None;
                break;
            }

            if (builder.EncodeType.Equals(Aspose.BarCode.Generation.EncodeTypes.None))
            {
                return(null);
            }

            builder.CodeText = parameters.BarcodeValue;

            if (builder.EncodeType.Equals(Aspose.BarCode.Generation.EncodeTypes.QR))
            {
                builder.Display2DText = parameters.BarcodeValue;
            }

            if (parameters.ForegroundColor != null)
            {
                builder.ForeColor = ConvertColor(parameters.ForegroundColor);
            }

            if (parameters.BackgroundColor != null)
            {
                builder.BackColor = ConvertColor(parameters.BackgroundColor);
            }

            if (parameters.SymbolHeight != null)
            {
                builder.ImageHeight = ConvertSymbolHeight(parameters.SymbolHeight);
                builder.AutoSize    = false;
            }

            builder.CodeLocation = CodeLocation.None;

            if (parameters.DisplayText)
            {
                builder.CodeLocation = CodeLocation.Below;
            }

            builder.CaptionAbove.Text = "";

            const float scale = 0.4f; // Empiric scaling factor for converting Word barcode to Aspose.BarCode
            float       xdim  = 1.0f;

            if (builder.EncodeType.Equals(Aspose.BarCode.Generation.EncodeTypes.QR))
            {
                builder.AutoSize    = false;
                builder.ImageWidth *= scale;
                builder.ImageHeight = builder.ImageWidth;
                xdim = builder.ImageHeight / 25;
                builder.xDimension = builder.yDimension = xdim;
            }

            if (parameters.ScalingFactor != null)
            {
                float scalingFactor = ConvertScalingFactor(parameters.ScalingFactor);
                builder.ImageHeight *= scalingFactor;
                if (builder.EncodeType.Equals(Aspose.BarCode.Generation.EncodeTypes.QR))
                {
                    builder.ImageWidth = builder.ImageHeight;
                    builder.xDimension = builder.yDimension = xdim * scalingFactor;
                }

                builder.AutoSize = false;
            }

#if NET462 || JAVA
            return(builder.BarCodeImage);
#elif NETCOREAPP2_1 || __MOBILE__
            builder.BarCodeImage.Save(ArtifactsDir + "GetBarcodeImage.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
        }