Exemple #1
0
        bool IMessageFilter.PreFilterMessage(ref Message m)
        {
            TwainCommand cmd = tw.PassMessage(ref m);

            if (cmd == TwainCommand.Null)
            {
                return(false);
            }

            if (cmd == TwainCommand.Not)
            {
                return(false);
            }

            switch (cmd)
            {
            case TwainCommand.CloseRequest:
            {
                EndingScan();
                tw.CloseSrc();
                break;
            }

            case TwainCommand.CloseOk:
            {
                EndingScan();
                tw.CloseSrc();
                break;
            }

            case TwainCommand.DeviceEvent:
            {
                break;
            }

            case TwainCommand.TransferReady:
            {
                ArrayList pics = tw.TransferPictures();
                EndingScan();
                tw.CloseSrc();

                for (int i = 0; i < pics.Count; i++)
                {
                    dibhand = (IntPtr)pics[i];
                    bmpptr  = GlobalLock(dibhand);
                    pixptr  = GetPixelInfo(bmpptr);

                    IntPtr img = IntPtr.Zero;
                    Guid   clsid;
                    String filename = "temp" + i + ".png";

                    if (!Gdip.GetCodecClsid(filename, out clsid))
                    {
                        return(false);
                    }

                    int st = Gdip.GdipCreateBitmapFromGdiDib(bmpptr, pixptr, ref img);

                    if ((st != 0) || (img == IntPtr.Zero))
                    {
                        return(false);
                    }

                    st = Gdip.GdipSaveImageToFile(img, filename, ref clsid, IntPtr.Zero);
                    Gdip.GdipDisposeImage(img);

                    addImageToPicturebox(filename);
                    actSaveToDb(null, null);
                    btnSaveToDb.Enabled = true;
                }
                break;
            }
            }
            return(true);
        }