Пример #1
0
        public void TestEncode()
        {
            Bitmap expectedBitmap = GetBitmapFromResource("Libdmtx.TestImages.Test001.png");

            byte[]        data          = Encoding.ASCII.GetBytes("Test");
            EncodeOptions opt           = new EncodeOptions();
            DmtxEncoded   encodeResults = Dmtx.Encode(data, opt);

            Assert.IsNotNull(encodeResults);
            AssertAreEqual(expectedBitmap, encodeResults.Bitmap);
        }
Пример #2
0
        public void TestStrideAndPadding()
        {
            EncodeOptions encodeOptions = new EncodeOptions {
                MarginSize = 2,
                ModuleSize = 2
            };
            DmtxEncoded encoded = Dmtx.Encode(Encoding.ASCII.GetBytes("t"), encodeOptions);
            Bitmap      bm      = encoded.Bitmap;

            // make sure we have an image who's stride is not divisable by 3
            int stride;

            ExecuteBitmapToByteArray(bm, out stride);
            if (stride % 3 == 0)
            {
                bm = BitmapIncreaseCanvas(bm, bm.Width + 1, bm.Height, Color.White);
                ExecuteBitmapToByteArray(bm, out stride);
            }
            Assert.AreNotEqual(0, stride % 3, "Stride was divisable by 3 which doesn't make a very good test");

            DecodeOptions opt = new DecodeOptions();
            Bitmap        diagnoseImage;

            DmtxDecoded[] decodedImages = Dmtx.Decode(bm, opt, DiagnosticImageStyles.Default, out diagnoseImage);

            //diagnoseImage.Save("c:/temp/diagnose.bmp", ImageFormat.Bmp);

            Assert.AreEqual(24.0, diagnoseImage.Width, 1.0);
            Assert.AreEqual(24.0, diagnoseImage.Height, 1.0);

            Assert.AreEqual(1, decodedImages.Length, "Didn't find barcode");

            // make sure the left line is straight up and down (not skewed)
            for (int y = 4; y < diagnoseImage.Height - 4; y++)
            {
                Color clrLeft  = diagnoseImage.GetPixel(1, y);
                Color clrRight = diagnoseImage.GetPixel(3, y);
                Assert.AreEqual(1.0, clrLeft.GetBrightness(), 0.01, "at location [1, " + y + "]");
                Assert.AreEqual(0.698, clrRight.GetBrightness(), 0.01, "at location [3, " + y + "]");
            }
        }