コード例 #1
0
        /// <summary>
        /// Draws the specified text using the supplied barcode metrics.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <param name="metrics">A <see cref="T:Zen.Barcode.BarcodeMetrics"/> object.</param>
        /// <returns>
        /// An <see cref="Image"/> object containing the rendered barcode.
        /// </returns>
        protected virtual DrawingGroup Draw1d(string text, BarcodeMetrics1d metrics)
        {
            // Determine number of pixels required for final image
            Glyph[] barcode = GetFullBarcode(text);

            // Determine amount of inter-glyph space
            int interGlyphSpace;

            if (metrics.InterGlyphSpacing.HasValue)
            {
                interGlyphSpace = metrics.InterGlyphSpacing.Value;
            }
            else
            {
                interGlyphSpace = GetDefaultInterGlyphSpace(metrics.MinWidth, metrics.MaxWidth);
            }

            // Determine bar code length in pixels
            int totalImageWidth = GetBarcodeLength(
                barcode,
                interGlyphSpace * metrics.Scale,
                metrics.MinWidth * metrics.Scale,
                metrics.MaxWidth * metrics.Scale);

            // Create image of correct size
            var drawingGroup = new DrawingGroup();

            //image.Width = totalImageWidth;
            //image.Height = metrics.MaxHeight;
            using (var dc = drawingGroup.Open())
            {
                var bounds = new Rect(0, 0, totalImageWidth, metrics.MaxHeight);
                Render(
                    barcode,
                    dc,
                    bounds,
                    interGlyphSpace * metrics.Scale,
                    metrics.MinHeight,
                    metrics.MinWidth * metrics.Scale,
                    metrics.MaxWidth * metrics.Scale);
            }

            // Handle rotation of image as necessary
            if (metrics.RenderVertically)
            {
                var rotation = new RotateTransform(
                    90,                   // Angle
                    totalImageWidth / 2,  // CenterX
                    metrics.MaxHeight / 2 // CenterY
                    );
                drawingGroup.Transform = rotation;
                //image.RotateFlip(RotateFlipType.Rotate90FlipNone);
            }

            return(drawingGroup);
        }
コード例 #2
0
        /// <summary>
        /// Draws the specified text using the supplied barcode metrics.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <param name="metrics">A <see cref="T:Zen.Barcode.BarcodeMetrics"/> object.</param>
        /// <returns>
        /// An <see cref="Image"/> object containing the rendered barcode.
        /// </returns>
        protected virtual Image Draw1d(string text, BarcodeMetrics1d metrics)
        {
            // Determine number of pixels required for final image
            Glyph[] barcode = GetFullBarcode(text);

            // Determine amount of inter-glyph space
            int interGlyphSpace;

            if (metrics.InterGlyphSpacing.HasValue)
            {
                interGlyphSpace = metrics.InterGlyphSpacing.Value;
            }
            else
            {
                interGlyphSpace = GetDefaultInterGlyphSpace(
                    metrics.MinWidth, metrics.MaxWidth);
            }

            // Determine bar code length in pixels
            int totalImageWidth = GetBarcodeLength(
                barcode,
                interGlyphSpace * metrics.Scale,
                metrics.MinWidth * metrics.Scale,
                metrics.MaxWidth * metrics.Scale);

            // Create image of correct size
            Bitmap image = new Bitmap(totalImageWidth, metrics.MaxHeight);

            using (Graphics dc = Graphics.FromImage(image))
            {
                Rectangle bounds = new Rectangle(0, 0, totalImageWidth, metrics.MaxHeight);
                Render(
                    barcode,
                    dc,
                    bounds,
                    interGlyphSpace * metrics.Scale,
                    metrics.MinHeight,
                    metrics.MinWidth * metrics.Scale,
                    metrics.MaxWidth * metrics.Scale);
            }

            // Handle rotation of image as necessary
            if (metrics.RenderVertically)
            {
                image.RotateFlip(RotateFlipType.Rotate90FlipNone);
            }

            return(image);
        }
コード例 #3
0
ファイル: BarcodeDraw.cs プロジェクト: xoware/xomanufacture
        /// <summary>
        /// Draws the specified text using the supplied barcode metrics.
        /// </summary>
        /// <param name="dc"></param>
        /// <param name="text">The text.</param>
        /// <param name="metrics">A <see cref="T:Zen.Barcode.BarcodeMetrics"/> object.</param>
        /// <param name="bounds"></param>
        /// <returns>
        /// An <see cref="ImageSource"/> object containing the rendered barcode.
        /// </returns>
        protected virtual void Draw1d(DrawingContext dc, string text, BarcodeMetrics1d metrics, Rect bounds)
        {
            // Determine number of pixels required for final image
            Glyph[] barcode = GetFullBarcode(text);

            // Determine amount of inter-glyph space
            double interGlyphSpace;

            if (metrics.InterGlyphSpacing.HasValue)
            {
                interGlyphSpace = metrics.InterGlyphSpacing.Value;
            }
            else
            {
                interGlyphSpace = GetDefaultInterGlyphSpace(
                    metrics.MinBarWidth, metrics.MaxBarWidth);
            }

            // Determine bar code length in pixels
            var totalImageWidth = GetBarcodeLength(
                barcode,
                interGlyphSpace * metrics.Scale,
                metrics.MinBarWidth * metrics.Scale,
                metrics.MaxBarWidth * metrics.Scale);

            var drawbounds = CalculateDrawBounds(bounds, totalImageWidth, metrics.MaxBarHeight);

            Render(
                barcode,
                dc,
                drawbounds,
                interGlyphSpace * metrics.Scale,
                metrics.MinBarHeight,
                metrics.MinBarWidth * metrics.Scale,
                metrics.MaxBarWidth * metrics.Scale);
        }