Ejemplo n.º 1
0
        private byte[] GetBitMatrix()
        {
            int width  = bm.GetWidth();
            int height = bm.GetHeight();
            int stride = (width + 7) / 8;

            byte[]    b  = new byte[stride * height];
            sbyte[][] mt = bm.GetArray();
            for (int y = 0; y < height; ++y)
            {
                sbyte[] line = mt[y];
                for (int x = 0; x < width; ++x)
                {
                    if (line[x] != 0)
                    {
                        int offset = stride * y + x / 8;
                        b[offset] |= (byte)(0x80 >> (x % 8));
                    }
                }
            }
            return(b);
        }
Ejemplo n.º 2
0
        /// <summary>* Places the barcode in a <CODE>PdfCanvas</CODE>.</summary>
        /// <remarks>
        /// * Places the barcode in a <CODE>PdfCanvas</CODE>. The
        /// barcode is always placed at coordinates (0, 0). Use the
        /// translation matrix to move it elsewhere.
        /// </remarks>
        /// <param name="canvas">the <CODE>PdfCanvas</CODE> where the barcode will be placed</param>
        /// <param name="foreground">the foreground color. It can be <CODE>null</CODE></param>
        /// <param name="moduleSide">the size of the square grid cell</param>
        /// <returns>the dimensions the barcode occupies</returns>
        public virtual Rectangle PlaceBarcode(PdfCanvas canvas, Color foreground, float moduleSide)
        {
            int width  = bm.GetWidth();
            int height = bm.GetHeight();

            byte[][] mt = bm.GetArray();
            if (foreground != null)
            {
                canvas.SetFillColor(foreground);
            }
            for (int y = 0; y < height; ++y)
            {
                byte[] line = mt[y];
                for (int x = 0; x < width; ++x)
                {
                    if (line[x] == 0)
                    {
                        canvas.Rectangle(x * moduleSide, (height - y - 1) * moduleSide, moduleSide, moduleSide);
                    }
                }
            }
            canvas.Fill();
            return(GetBarcodeSize(moduleSide));
        }