Пример #1
0
        public ActionResult Index(ScannModel model, string scannedImage)
        {
            string   fileName        = "captured.png";
            string   fileNameWitPath = Path.Combine(Server.MapPath("~/images"), fileName);
            FileInfo fi = new FileInfo(fileNameWitPath);

            if (!Directory.Exists(fi.DirectoryName))
            {
                Directory.CreateDirectory(fi.DirectoryName);
            }

            using (FileStream fs = new FileStream(fileNameWitPath, FileMode.OpenOrCreate))
            {
                using (BinaryWriter bw = new BinaryWriter(fs))
                {
                    byte[] data = Convert.FromBase64String(scannedImage);
                    bw.Write(data);
                    bw.Close();
                }
                fs.Close();
            }

            BarCodeDecoder decoder = new BarCodeDecoder();
            var            content = decoder.Read(scannedImage);

            return(View(SearchProduct(content)));
        }
Пример #2
0
        public void DecoderTest()
        {
            BarCodeDecoder decoder = new BarCodeDecoder();
            Bitmap         bitmap  = new Bitmap("captured.png");

            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {
                bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                byte[] byteImage = ms.ToArray();
                var    imageData = Convert.ToBase64String(byteImage); //Get Base64
                var    result    = decoder.Read(imageData);

                Assert.AreEqual(result, "096619321841");
            }
        }