Example #1
0
        void OnSetupMemXferEvent(object sender, Twain32.SetupMemXferEventArgs e)
        {
            if (stream != null)
            {
                FinishImageTransfer();
            }
            logger.Debug("SetupMemXfer size={0}B", e.ImageInfo.BitsPerPixel * e.ImageInfo.ImageLength * e.ImageInfo.ImageWidth / 8);
            try {
                stream = new MemoryStream((int)e.BufferSize);
                var _writer = new BinaryWriter(this.stream);
                switch (e.ImageInfo.BitsPerPixel)
                {
                case 1:
                    if (e.ImageInfo.PixelType == TwPixelType.Palette)
                    {
                        _writer.Write(Encoding.ASCII.GetBytes("P6\n"));
                        this.palette = this._twain32.Palette.Get();
                    }
                    else
                    {
                        _writer.Write(Encoding.ASCII.GetBytes("P5\n"));
                    }
                    break;

                case 3:
                    _writer.Write(Encoding.ASCII.GetBytes("P6\n"));
                    break;

                default:
                    _writer.Write(Encoding.ASCII.GetBytes("PX\n"));
                    break;
                }
                _writer.Write(Encoding.ASCII.GetBytes(string.Format("# (C) SARAFF SOFTWARE 2013.\n{0} {1}\n{2}\n", e.ImageInfo.ImageWidth, e.ImageInfo.ImageLength, byte.MaxValue)));
                OnPulse(e.ImageInfo.BitsPerPixel * e.ImageInfo.ImageLength * e.ImageInfo.ImageWidth / 8, (int)stream.Position);
            } catch (Exception ex)
            {
                logger.Error(ex, "Ошибка при настройке буфера приема.");
                throw ex;
            }
        }
Example #2
0
 void OnSetupMemXferEvent(object sender, Twain32.SetupMemXferEventArgs e)
 {
     if (stream != null)
         FinishImageTransfer ();
     logger.Debug("SetupMemXfer size={0}B", e.ImageInfo.BitsPerPixel * e.ImageInfo.ImageLength * e.ImageInfo.ImageWidth / 8);
     try {
         stream = new MemoryStream((int)e.BufferSize);
         var _writer=new BinaryWriter(this.stream);
         switch(e.ImageInfo.BitsPerPixel) {
         case 1:
             if(e.ImageInfo.PixelType==TwPixelType.Palette) {
                 _writer.Write(Encoding.ASCII.GetBytes("P6\n"));
                 this.palette=this._twain32.Palette.Get();
             } else {
                 _writer.Write(Encoding.ASCII.GetBytes("P5\n"));
             }
             break;
         case 3:
             _writer.Write(Encoding.ASCII.GetBytes("P6\n"));
             break;
         default:
             _writer.Write(Encoding.ASCII.GetBytes("PX\n"));
             break;
         }
         _writer.Write(Encoding.ASCII.GetBytes(string.Format("# (C) SARAFF SOFTWARE 2013.\n{0} {1}\n{2}\n",e.ImageInfo.ImageWidth,e.ImageInfo.ImageLength,byte.MaxValue)));
         OnPulse(e.ImageInfo.BitsPerPixel * e.ImageInfo.ImageLength * e.ImageInfo.ImageWidth / 8, (int)stream.Position);
     } catch(Exception ex)
     {
         logger.Error (ex, "Ошибка при настройке буфера приема.");
         throw ex;
     }
 }