Beispiel #1
0
        private void btnAcquire_Click(object sender, EventArgs e)
        {
            try
            {
                btnAcquire.Enabled = false;

                if (String.IsNullOrEmpty(textBox1.Text))//If device name is null or empty return.
                {
                    btnAcquire.Enabled = true;
                    MessageBox.Show("Add save path");
                    return;
                }


                //  _asyncDS = _asyncDSM.OpenSource();

                _asyncDS.OnSingleImageAcquired += _asyncDS_ImageAcquired;//Event image acquired.
                ImageCollector col    = new ImageCollector();
                bool           showUI = false;
                _asyncDS.AcquireAsync(asyncDS_OnScanFinished, showUI, false, TwainScanning.NativeStructs.TwSX.Native, -1);//Acquire image async.
            }
            catch (TwainScanning.BadRcTwainException ex)
            {
                btnAcquire.Enabled = true;
                MessageBox.Show("Bad twain return code: " + ex.ReturnCode.ToString() + "\nCondition code: " + ex.ConditionCode.ToString() + "\n" + ex.Message);
            }
            CloseDs();
            btnAcquire.Enabled = true;
        }
Beispiel #2
0
 void asyncDS_OnScanFinished(ImageCollector collector)
 {
     btnAcquire.Enabled = true;
     if (String.IsNullOrEmpty(textBox1.Text))
     {
         return;//If device name is null or empty return.
     }
     if (collector != null)
     {
         string pathPDF  = "";
         string pathTIFF = "";
         int    i        = 0;
         do
         {
             string dir         = Path.GetDirectoryName(textBox1.Text);
             string noExtension = Path.GetFileNameWithoutExtension(textBox1.Text);
             pathPDF  = dir + "\\" + noExtension + i + ".pdf";
             pathTIFF = dir + "\\" + noExtension + i + ".tiff";
             i++;
         }while (File.Exists(pathPDF));
         collector.SaveAllToMultipagePdf(pathPDF);
         collector.SaveAllToMultipageTiff(pathTIFF);
         collector.Dispose();
     }
     CloseDs();
 }
        public void TestImageCollector()
        {
            Mock <IWebpageProvider> providerMock = new Mock <IWebpageProvider>();

            providerMock.Setup(prov => prov.Download(It.IsAny <string>())).Returns(XDocument.Parse(Resources.mock_result_data));

            ImageCollector imCollector = new ImageCollector(providerMock.Object);

            IList <ImageData> images = imCollector.GetImages("http://www.abc.hu/index.html");

            ImageData[] imagesAsArray = images.ToArray();

            Assert.AreEqual(new ImageData("http://www.abc.hu/pic1.bmp"), imagesAsArray[0]);
            Assert.AreEqual(new ImageData("http://www.abc.hu/pic2.bmp"), imagesAsArray[1]);
            Assert.AreEqual(new ImageData("http://www.abc.hu/pic3.bmp"), imagesAsArray[2]);
        }