public static void ImplementDotCodeForBarcode()
 {
     //ExStart: ImplementDotCodeForBarcode
     using (BarCodeGenerator generator = new BarCodeGenerator(EncodeTypes.DotCode))
     {
         generator.DotCodeMask = 2;
         Bitmap barcode = generator.GenerateBarCodeImage();
         barcode.Save(dataDir + "DotCode.png");
     }
     //ExEnd: ImplementDotCodeForBarcode
 }
Ejemplo n.º 2
0
 public BitmapSource CreateQRBarcode(int size, string textData)
 {
     using (var generator = new BarCodeGenerator(EncodeTypes.QR, textData))
     {
         generator.AutoSizeMode         = AutoSizeMode.Nearest;
         generator.BarCodeWidth.Pixels  = size;
         generator.BarCodeHeight.Pixels = size;
         generator.D2.DisplayText       = string.Empty;
         var image = generator.GenerateBarCodeImage().ToBitmapSource();
         image.Freeze();
         return(image);
     }
 }
        public static void ImplementInterpolationAutoSizemode()
        {
            //ExStart: ImplementInterpolationAutoSizemode
            using (BarCodeGenerator generator = new BarCodeGenerator(EncodeTypes.DataMatrix))
            {
                generator.AutoSizeMode             = AutoSizeMode.Interpolation;
                generator.BarCodeWidth.Millimeters = 50;
                generator.BarCodeHeight.Inches     = 1.3f;

                Bitmap barcode = generator.GenerateBarCodeImage();
                barcode.Save(dataDir + "DataMatrix.png");
            }
            //ExEnd: ImplementInterpolationAutoSizemode
        }
Ejemplo n.º 4
0
        public BitmapSource CreateBarcode(GenerationData barcodeData)
        {
            var encodeType = barcodeData.Type.GetEncodeType();

            using (var generator = new BarCodeGenerator(encodeType, barcodeData.Data))
            {
                generator.ThrowExceptionWhenCodeTextIncorrect = barcodeData.ValidateCodeText;
                generator.AutoSizeMode   = AutoSizeMode.Nearest;
                generator.EnableEscape   = true;
                generator.ITF.BorderType = ITF14BorderType.None;
                HideTexts(generator);
                FitSizes(generator, barcodeData);
                var barcodeImage        = generator.GenerateBarCodeImage();
                var barcodeBitmapSource = barcodeImage.ToBitmapSource();
                barcodeBitmapSource.Freeze();
                return(barcodeBitmapSource);
            }
        }
Ejemplo n.º 5
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);
            }

            string type       = parameters.BarcodeType.ToUpper();
            var    encodeType = EncodeTypes.None;

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

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

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

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

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

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

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

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

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

            //builder.EncodeType = ConvertBarcodeType(parameters.BarcodeType);
            if (encodeType == Aspose.BarCode.Generation.EncodeTypes.None)
            {
                return(null);
            }

            BarCodeGenerator builder = new BarCodeGenerator(encodeType);

            builder.CodeText = parameters.BarcodeValue;

            if (encodeType == Aspose.BarCode.Generation.EncodeTypes.QR)
            {
                builder.D2.DisplayText = 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.BarCodeHeight.Millimeters = ConvertSymbolHeight(parameters.SymbolHeight);
                builder.AutoSizeMode = AutoSizeMode.Nearest;
            }

            builder.CodeTextStyle.Location = CodeLocation.None;

            if (parameters.DisplayText)
            {
                builder.CodeTextStyle.Location = 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 (encodeType == Aspose.BarCode.Generation.EncodeTypes.QR)
            {
                builder.AutoSizeMode              = AutoSizeMode.Nearest;
                builder.BarCodeWidth.Millimeters *= scale;
                builder.BarCodeHeight.Millimeters = builder.BarCodeWidth.Millimeters;
                xdim = builder.BarCodeHeight.Millimeters / 25;
                builder.XDimension.Millimeters = builder.BarHeight.Millimeters = xdim;
            }

            if (parameters.ScalingFactor != null)
            {
                float scalingFactor = ConvertScalingFactor(parameters.ScalingFactor);
                builder.BarCodeHeight.Millimeters *= scalingFactor;
                if (encodeType == Aspose.BarCode.Generation.EncodeTypes.QR)
                {
                    builder.BarCodeWidth.Millimeters = builder.BarCodeHeight.Millimeters;
                    builder.XDimension.Millimeters   = builder.BarHeight.Millimeters = xdim * scalingFactor;
                }

                builder.AutoSizeMode = AutoSizeMode.Nearest;
            }
            return(builder.GenerateBarCodeImage());
        }