public Bitmap DeskewImage(Bitmap image) { Deskew sk = new Deskew(image); double skewAngle = sk.GetSkewAngle(); return Rotate(image, (float)(-skewAngle)); }
public Bitmap DeskewImage(Bitmap image) { Deskew sk = new Deskew(image); double skewAngle = sk.GetSkewAngle(); return(Rotate(image, (float)(-skewAngle))); }
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); } }
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); } }