private void _twain32_EndXfer(object sender, Twain32.EndXferEventArgs e) { logger.Debug("EndXfer fired"); if (e.Image != null) { Pixbuf CurImg = WinImageToPixbuf(e.Image); e.Image.Dispose(); if (ImageTransfer == null) { // Записываем во внутренний массив Images.Add(CurImg); } else { // Передаем через событие ImageTransferEventArgs arg = new ImageTransferEventArgs(); arg.AllImages = TotalImages; arg.Image = CurImg; ImageTransfer(this, arg); } } }
private void FinishImageTransfer() { if (stream != null) { stream.Position = 0; Pixbuf CurImg = new Pixbuf(stream); stream.Close(); stream = null; if (ImageTransfer == null) { // Записываем во внутренний массив Images.Add(CurImg); } else { // Передаем через событие ImageTransferEventArgs arg = new ImageTransferEventArgs(); arg.AllImages = TotalImages; arg.Image = CurImg; CurrentImage++; ImageTransfer(this, arg); } } }
private void _twain32_AcquireCompleted(object sender, EventArgs e) { logger.Debug("Acquire Completed"); //FIXME Если не будет использоваться нативный режим событие не нужно. TotalImages = _twain32.ImageCount; for (int i = 0; i < _twain32.ImageCount; i++) { System.Drawing.Image WinImg = _twain32.GetImage(i); Pixbuf CurImg = WinImageToPixbuf(WinImg); WinImg.Dispose(); if (ImageTransfer == null) { // Записываем во внутренний массив Images.Add(CurImg); } else { // Передаем через событие ImageTransferEventArgs arg = new ImageTransferEventArgs(); arg.AllImages = TotalImages; arg.Image = CurImg; ImageTransfer(this, arg); } } logger.Debug("Data Transferred"); }
private void _Acquire() { TwainExternalProcess.Execute( System.IO.Path.Combine(System.IO.Path.GetDirectoryName(this.GetType().Assembly.Location), this._CurrentDataSource.ExecFileName), twain => { #region Native twain.EndXfer += (sender, e) => Gtk.Application.Invoke(delegate { logger.Debug("EndXfer fired"); if (e.Image != null) { Pixbuf CurImg = WinImageToPixbuf(e.Image); e.Image.Dispose(); if (ImageTransfer == null) { // Записываем во внутренний массив Images.Add(CurImg); } else { // Передаем через событие ImageTransferEventArgs arg = new ImageTransferEventArgs(); arg.AllImages = TotalImages; arg.Image = CurImg; ImageTransfer(this, arg); } } }); #endregion #region File /* twain.SetupFileXferEvent+=(sender, e) => { * try { * var _dlg=new Microsoft.Win32.SaveFileDialog { * Filter=String.Format("{0}-files|*.{0}", (this.imageFileFormExpander.Content as ListBox).SelectedValue.ToString().ToLower()), * OverwritePrompt=true * }; * if((bool)_dlg.ShowDialog()) { * e.FileName=_dlg.FileName; * } else { * e.Cancel=true; * } * } catch { * } * }; * * twain.FileXferEvent+=(sender, e) => { * try { * if(System.IO.Path.GetExtension(e.ImageFileXfer.FileName)==".tmp") { * Win32.MoveFileEx(e.ImageFileXfer.FileName, null, Win32.MoveFileFlags.DelayUntilReboot); * } * var _img=new BitmapImage(new Uri(e.ImageFileXfer.FileName)); * _img.Freeze(); * this.Dispatcher.BeginInvoke( * new Action(() => { * try { * this.scanImage.Source=_img; * } catch(Exception ex) { * ex.ErrorMessageBox(); * } * }) * ); * } catch { * } * }; */ #endregion #region Memory /* #region SetupMemXferEvent * * twain.SetupMemXferEvent+=(sender, e) => { * try { * System.Windows.Media.PixelFormat _format=PixelFormats.Default; * BitmapPalette _pallete=null; * switch(e.ImageInfo.PixelType) { * case TwPixelType.BW: * _format=PixelFormats.BlackWhite; * break; * case TwPixelType.Gray: * _format=new Dictionary<short, System.Windows.Media.PixelFormat> { * {2,PixelFormats.Gray2}, * {4,PixelFormats.Gray4}, * {8,PixelFormats.Gray8}, * {16,PixelFormats.Gray16} * }[e.ImageInfo.BitsPerPixel]; * break; * case TwPixelType.Palette: * _pallete=new BitmapPalette(new Func<IList<Color>>(() => { * var _res=new Collection<Color>(); * var _colors=twain.Palette.Get().Colors; * for(int i=0; i<_colors.Length; i++) { * _res.Add(Color.FromArgb(_colors[i].A, _colors[i].R, _colors[i].G, _colors[i].B)); * } * return _res; * })()); * _format=new Dictionary<short, System.Windows.Media.PixelFormat> { * {2,PixelFormats.Indexed1}, * {4,PixelFormats.Indexed2}, * {8,PixelFormats.Indexed4}, * {16,PixelFormats.Indexed8} * }[e.ImageInfo.BitsPerPixel]; * break; * case TwPixelType.RGB: * _format=new Dictionary<short, System.Windows.Media.PixelFormat> { * {8,PixelFormats.Rgb24}, * {24,PixelFormats.Rgb24}, * {16,PixelFormats.Rgb48}, * {48,PixelFormats.Rgb48} * }[e.ImageInfo.BitsPerPixel]; * break; * default: * throw new InvalidOperationException("Данный формат пикселей не поддерживается."); * } * * this.Dispatcher.BeginInvoke( * new Action(() => { * try { * this.scanImage.Source=new WriteableBitmap( * e.ImageInfo.ImageWidth, * e.ImageInfo.ImageLength, * e.ImageInfo.XResolution, * e.ImageInfo.YResolution, * _format, * _pallete); * } catch(Exception ex) { * ex.ErrorMessageBox(); * } * }) * ); * * } catch { * } * }; * #endregion * * twain.MemXferEvent+=(sender, e) => { * try { * this.Dispatcher.BeginInvoke( * new Action(() => { * try { * (this.scanImage.Source as WriteableBitmap).WritePixels( * new Int32Rect(0, 0, (int)e.ImageMemXfer.Columns, (int)e.ImageMemXfer.Rows), * e.ImageMemXfer.ImageData, * (int)e.ImageMemXfer.BytesPerRow, * (int)e.ImageMemXfer.XOffset, * (int)e.ImageMemXfer.YOffset); * } catch(Exception ex) { * ex.ErrorMessageBox(); * } * }) * ); * } catch { * } * }; */ #endregion #region Set Capabilities twain.SourceIndex = currentScanner; twain.ShowUI = true; twain.OpenDataSource(); twain.Capabilities.XferMech.Set(TwSX.Native); /* try { * twain.SetCap(TwCap.XResolution, (float)(this.resolutionExpander.Content as ListBox).SelectedValue); * } catch { * } * * try { * twain.SetCap(TwCap.YResolution, (float)(this.resolutionExpander.Content as ListBox).SelectedValue); * } catch { * } * * try { * twain.SetCap(TwCap.IPixelType, (TwPixelType)(this.pixelTypeExpander.Content as ListBox).SelectedValue); * } catch { * } * * try { * twain.SetCap(TwCap.IXferMech, (TwSX)(this.xferMechExpander.Content as ListBox).SelectedValue); * } catch { * } * * try { * twain.SetCap(TwCap.ImageFileFormat, (TwFF)(this.imageFileFormExpander.Content as ListBox).SelectedValue); * } catch { * } * * try { * twain.Capabilities.Indicators.Set(false); * } catch { * } */ twain.Capabilities.XferCount.Set(1); #endregion twain.Acquire(); }); }
void OnScanWorksImageTransfer(object s, ImageTransferEventArgs arg) { TreeIter iter; progresswork.Text = "Завершаем загрузку..."; MainClass.WaitRedraw(); logger.Debug("ImageTransfer event"); iter = ImageListNewDoc(); Pixbuf image = arg.Image; double ratio = 150f / Math.Max(image.Height, image.Width); Pixbuf thumb = image.ScaleSimple((int)(image.Width * ratio),(int)(image.Height * ratio), InterpType.Bilinear); ImageList.AppendValues (iter, 0, null, null, null, thumb, image, true, "", ""); progresswork.Text = "Ок"; progresswork.Adjustment.Value = progresswork.Adjustment.Upper; MainClass.WaitRedraw(); }
void OnScanerImageTransfer(object sender, ImageTransferEventArgs e) { progressScan.Text = "Завершаем загрузку..."; logger.Debug("ImageTransfer event"); vimageslist1.Images.Add (e.Image); progressScan.Text = "Ок"; progressScan.Adjustment.Value = progressScan.Adjustment.Upper; QSMain.WaitRedraw(); }
private void _twain32_EndXfer(object sender,Twain32.EndXferEventArgs e) { logger.Debug("EndXfer fired"); if(e.Image!=null) { Pixbuf CurImg = WinImageToPixbuf(e.Image); e.Image.Dispose(); if(ImageTransfer == null) {// Записываем во внутренний массив Images.Add(CurImg); } else {// Передаем через событие ImageTransferEventArgs arg = new ImageTransferEventArgs(); arg.AllImages = TotalImages; arg.Image = CurImg; ImageTransfer(this, arg); } } }
private void _twain32_AcquireCompleted(object sender,EventArgs e) { logger.Debug("Acquire Completed"); //FIXME Если не будет использоваться нативный режим событие не нужно. TotalImages = _twain32.ImageCount; for(int i = 0; i < _twain32.ImageCount; i++) { System.Drawing.Image WinImg = _twain32.GetImage(i); Pixbuf CurImg = WinImageToPixbuf(WinImg); WinImg.Dispose(); if(ImageTransfer == null) {// Записываем во внутренний массив Images.Add(CurImg); } else {// Передаем через событие ImageTransferEventArgs arg = new ImageTransferEventArgs(); arg.AllImages = TotalImages; arg.Image = CurImg; ImageTransfer(this, arg); } } logger.Debug("Data Transferred"); }
private void FinishImageTransfer() { if(stream != null) { stream.Position = 0; Pixbuf CurImg = new Pixbuf(stream); stream.Close (); stream = null; if(ImageTransfer == null) {// Записываем во внутренний массив Images.Add(CurImg); } else {// Передаем через событие ImageTransferEventArgs arg = new ImageTransferEventArgs(); arg.AllImages = TotalImages; arg.Image = CurImg; CurrentImage++; ImageTransfer(this, arg); } } }