示例#1
0
        public void StartScanning()
        {
            Scanner device = null;

            this.Invoke(new MethodInvoker(delegate () { device = comboBox3.SelectedItem as Scanner; }));

            if (device == null)
            {
                MessageBox.Show("Nie wybrano skanera!", "Ostrzezenie", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else if (String.IsNullOrEmpty(textBox2.Text))
            {
                MessageBox.Show("Wprowadz nazwe pliku!", "Ostrzezenie", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            ImageFile image = new ImageFile();
            string imageExtension = "";
            device.SetResolution(resolution);
            this.Invoke(new MethodInvoker(delegate ()
            {
                switch (comboBox1.SelectedIndex)
                {
                    case 0:
                        image = device.ScanPNG();
                        imageExtension = ".png";
                        break;
                    case 1:
                        image = device.ScanJPEG();
                        imageExtension = ".jpeg";
                        break;
                    case 2:
                        image = device.ScanTIFF();
                        imageExtension = ".tiff";
                        break;
                }
            }));

            // Save the image
            path = Path.Combine(textBox2.Text + imageExtension);

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

            image.SaveFile(path);

            pictureBox1.Image = new Bitmap(path);
        }