示例#1
0
        protected void CreatePicture()
        {
            int    width           = (((int)this.Width.Value) * this.resolutiondpi) / 0x60;
            int    height          = (((int)this.Height.Value) * this.resolutiondpi) / 0x60;
            string encodebinarystr = "";
            string str             = this.text;
            string checkStr        = "";

            if (this.barType == BarType.PDF417)
            {
                str = this.text;
            }
            if (this.barType == BarType.PDF417)
            {
                encodebinarystr = this.GetPDF417Str(0x60, str);
            }
            else if (this.barType == BarType.DataMatrix)
            {
                encodebinarystr = this.GetDataMatrixStr(str);
            }
            else if (this.barType < BarType.PDF417)
            {
                LinearEncoder encoder = new LinearEncoder();
                encoder.narrowratio = this.ratio;
                if (((this.barType != BarType.Code39) && (this.barType != BarType.Code25)) && ((this.barType != BarType.I25) && (this.barType != BarType.Codabar)))
                {
                    this.addcheckdigit = true;
                }
                string demoStr  = null;
                string drawText = null;
                encodebinarystr = encoder.Encoding((int)this.barType, ref str, this.addcheckdigit, out checkStr, out demoStr, out drawText);
            }
            this.picture = new Bitmap(width, height);
            this.picture.SetResolution((float)this.resolutiondpi, (float)this.resolutiondpi);
            Graphics g = Graphics.FromImage(this.picture);

            if (this.barType == BarType.PDF417)
            {
                PDF417Image image = new PDF417Image();
                this.InitPDF417Img(ref this.picture, ref image, encodebinarystr, this.resolutiondpi, width, height);
                image.DrawPDF417(ref g);
            }
            else if (this.barType == BarType.DataMatrix)
            {
                DataMatrixImage datamatriximg = new DataMatrixImage();
                this.InitDataMatrixImg(ref this.picture, ref datamatriximg, encodebinarystr, this.resolutiondpi, width, height);
                datamatriximg.DrawDataMatrix(ref g);
            }
            else if (this.barType < BarType.PDF417)
            {
                LinearImage image3 = new LinearImage();
                this.InitLinearImg(ref this.picture, ref image3, checkStr, str, encodebinarystr, this.resolutiondpi, width, height);
                image3.DrawLinear(ref g);
            }
            g.Dispose();
        }
示例#2
0
        public static List <LargeInteger> ReadLinearCoder(LinearEncoder coder)
        {
            var data = coder.ReadData(0);

            var ret = new List <LargeInteger>();

            foreach (var byteArray in data)
            {
                ret.Add(new LargeInteger(byteArray));
            }

            return(ret);
        }
示例#3
0
        private Bitmap GetLinearBitmap()
        {
            string        checkStr;
            string        demoStr;
            string        drawText;
            LinearEncoder encoder = new LinearEncoder();

            encoder.narrowratio = this.ratio;
            if (((this.symbology != 0) && (this.symbology != 10)) && ((this.symbology != 11) && (this.symbology != 13)))
            {
                this.addcheckdigit = true;
            }
            string      text4  = encoder.Encoding(this.symbology, ref this.texttoencode, this.addcheckdigit, out checkStr, out demoStr, out drawText);
            Bitmap      bitmap = new Bitmap(this.symbolwidth, this.symbolheight);
            Graphics    g      = Graphics.FromImage(bitmap);
            LinearImage image  = new LinearImage();

            image.encodebinarystr           = text4;
            image.encodestr                 = this.texttoencode;
            image.symbolwidth               = this.symbolwidth;
            image.symbolheight              = this.symbolheight;
            image.narrowbarwidth            = this.narrowbarwidth;
            image.barheight                 = this.barheight;
            image.leftmargin                = this.leftmargin;
            image.topmargin                 = this.topmargin;
            image.textmargin                = this.textmargin;
            image.forecolor                 = this.forecolor;
            image.backcolor                 = this.backcolor;
            image.symbology                 = this.symbology;
            image.checkstr                  = checkStr;
            image.addcheckdigittotext       = this.addcheckdigittotext;
            image.showtext                  = this.showtext;
            image.txtFont                   = new Font(this.fontname, (float)this.fontsize);
            image.topcomment                = this.topcomment;
            image.bottomcomment             = this.bottomcomment;
            image.topcommenttopmargin       = this.topcommenttopmargin;
            image.topcommentleftmargin      = this.topcommentleftmargin;
            image.bottomcommentleftmargin   = this.bottomcommentleftmargin;
            image.bottomcommentbottommargin = this.bottomcommentbottommargin;
            image.bearerbars                = this.bearerbars;
            image.texttostretch             = this.texttostretch;
            image.resolutiondpi             = 0x60;
            image.textalignment             = this.textalignment;
            image.DrawLinear(ref g);
            g.Dispose();
            return(bitmap);
        }
示例#4
0
        public void LinearOffsetCoderUnitTest()
        {
            string path = "linearCoderTest";

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            var linearCoder = new LinearEncoder(path, 64);

            var expected = new byte[15][];

            for (int i = 0; i < expected.Length; i++)
            {
                expected[i] = new byte[64];

                for (int j = 0; j < 64; j++)
                {
                    expected[i][j] = (byte)(33 + j + i); //test data
                }
            }

            linearCoder.Append(expected);

            var actual = linearCoder.ReadData();

            for (int i = 0; i < expected.Length; i++)
            {
                Assert.IsTrue(ArrayManipulator.Compare(expected[i], actual[i]));
            }

            Assert.AreEqual(expected.Length, linearCoder.Count);

            linearCoder.Remove(1);

            Assert.AreEqual((byte)35, linearCoder.ReadData()[1][0]);
        }