예제 #1
0
        public void InitScan()
        {
            ImageProc         imgP = new ImageProc();
            CommonDialogClass commonDialogClass = new CommonDialogClass();

            DeviceIdCmb.SelectedIndex = DeviceCmb.SelectedIndex;
            try
            {
                if (DeviceCmb.Items.Count == 0)
                {
                    MessageBox.Show("Please connect a scanner.");
                }
                Deskew _deskew = new Deskew();

                scanSettings _scanSettings = new scanSettings();

                List <System.Drawing.Image> images = null;
                images = WIAScanner.AutoScan((string)DeviceIdCmb.SelectedItem, Convert.ToInt32(dpiTxt.Text), (Convert.ToDouble(cropxTxt.Text)), (Convert.ToDouble(cropyTxt.Text)),
                                             (Convert.ToDouble(widthTxt.Text) * Convert.ToDouble(dpiTxt.Text)), (Convert.ToDouble(heightTxt.Text) * Convert.ToDouble(dpiTxt.Text)), (int)parseSettings("Brightness"),
                                             (int)parseSettings("Contrast"), (int)parseSettings("Color Mode"));
                selRect.Visibility = Visibility.Collapsed;
                foreach (System.Drawing.Image image in images)
                {
                    if ((int)parseSettings("Bpp") == 1)
                    {
                        ScanView.Source = ImageProc.setPixelFormat1(ImageProc.ImgToBmpSource(image), PixelFormats.BlackWhite);
                        saveImageAsFile(ImageProc.setPixelFormat2(ImageProc.ImgToBmpSource(image), System.Drawing.Imaging.PixelFormat.Format1bppIndexed));
                    }
                    if ((int)parseSettings("Bpp") == 8)
                    {
                        BitmapSource img8bit = ImageProc.setPixelFormat1(ImageProc.ImgToBmpSource(image), PixelFormats.Gray8);
                        ScanView.Source = img8bit;
                        saveImageAsFile(ImageProc.BmpSource2Img(img8bit));
                    }
                    if ((int)parseSettings("Bpp") == 24)
                    {
                        ScanView.Source = ImageProc.setPixelFormat1(ImageProc.ImgToBmpSource(image), PixelFormats.Bgr24);
                        saveImageAsFile(ImageProc.setPixelFormat2(ImageProc.ImgToBmpSource(image), System.Drawing.Imaging.PixelFormat.Format24bppRgb));
                    }
                    if ((int)parseSettings("Bpp") == 32)
                    {
                        ScanView.Source = ImageProc.setPixelFormat1(ImageProc.ImgToBmpSource(image), PixelFormats.Bgr32);
                        saveImageAsFile(ImageProc.setPixelFormat2(ImageProc.ImgToBmpSource(image), System.Drawing.Imaging.PixelFormat.Format32bppRgb));
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Unexpected Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
예제 #2
0
        private void previewScan()
        {
            CommonDialogClass commonDialogClass = new CommonDialogClass();

            DeviceIdCmb.SelectedIndex = DeviceCmb.SelectedIndex;
            try
            {
                if (DeviceCmb.Items.Count == 0)
                {
                    MessageBox.Show("Please connect a scanner.");
                }

                List <System.Drawing.Image> images = WIAScanner.preScan((string)DeviceIdCmb.SelectedItem);
                foreach (System.Drawing.Image img in images)
                {
                    //ScanView.Source = ImgToBmpSource(img);

                    /*Bitmap bmp = new Bitmap(img);
                     * Grayscale gs_fil = new Grayscale(0.2125, 0.7154, 0.0721);
                     * Bitmap gs_Bmp = gs_fil.Apply(bmp);
                     * DocumentSkewChecker skewCheck = new DocumentSkewChecker();
                     * double angle = skewCheck.GetSkewAngle(gs_Bmp);
                     * RotateBilinear rotateFilter = new RotateBilinear(-angle);
                     * rotateFilter.FillColor = System.Drawing.Color.White;
                     * Bitmap rotatedImage = rotateFilter.Apply(gs_Bmp);
                     * new ContrastStretch().ApplyInPlace(gs_Bmp);
                     * new Threshold(180).ApplyInPlace(gs_Bmp);
                     * //new Invert().ApplyInPlace(gs_Bmp);
                     * BlobCounter bc = new BlobCounter();
                     *
                     * bc.FilterBlobs = true;
                     * bc.ProcessImage(gs_Bmp);
                     * System.Drawing.Rectangle[] rects = bc.GetObjectsRectangles();*/
                    PreView.Source = ImageProc.ImgToBmpSource(img);
                    //gs_Bmp.Save(userProfile + "\\Pictures\\TreshSample1.png", ImageFormat.Png);

                    /* foreach (System.Drawing.Rectangle rect in rects)
                     * {
                     *   cropxTxt.Text = (rect.Left).ToString();
                     *   cropyTxt.Text = (rect.Top / 5).ToString();
                     *   heightTxt.Text = (rect.Bottom).ToString();
                     *   widthTxt.Text = (rect.Right / 45).ToString();
                     * }*/
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Unexpected Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
예제 #3
0
        private void getDevices()
        {
            DeviceCmb.Items.Clear();
            DeviceIdCmb.Items.Clear();
            try
            {
                List <string> devices   = WIAScanner.GetDevices();
                List <string> deviceIds = WIAScanner.GetDevicesId();

                foreach (string deviceId in deviceIds)
                {
                    DeviceIdCmb.Items.Add(deviceId);
                }
                foreach (string device in devices)
                {
                    DeviceCmb.Items.Add(device);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Unexpected Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }