Esempio n. 1
0
        bool IMessageFilter.PreFilterMessage(ref Message m)
        {
            TwainCommand cmd = tw.PassMessage(ref m);
            if (cmd == TwainCommand.Null)
            {
                EndingScan();
                tw.CloseSrc();
                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();
                        picnumber++;
                        if (pics.Count > 0)
                        {

                        }
                        for (int i = 0; i < pics.Count; i++)
                        {
                            IntPtr img = (IntPtr)pics[i];

                            dibhand = img;
                            bmpptr = GlobalLock(dibhand);
                            pixptr = GetPixelInfo(bmpptr);
                            //Bitmap map = new Bitmap(130, 170);
                            Bitmap map = new Bitmap(bmprect.Width, bmprect.Height);
                            Graphics scannedImageGraphics = Graphics.FromImage(map);

                            IntPtr hdc = scannedImageGraphics.GetHdc();
                            // IntPtr hdc = map.GetHbitmap();
                            SetDIBitsToDevice(hdc, 0, 0, bmprect.Width, bmprect.Height,
                                    0, 0, 0, bmprect.Height, pixptr, bmpptr, 0);
                            scannedImageGraphics.ReleaseHdc(hdc);

                            // map.Save("c:\\tempgetimageformdevice.bmp");
                            // this.pictureBox1.Image = map;
                            if (set.CapWidth== set.DevWidth &&set.CapHeight ==  set.DevHeight)
                            {
                                this.picPic.Image = map;
                                this.SavePic();
                            }
                            else
                            {
                            CaptureImage form = new CaptureImage(map, this.picPic,set);
                            form.ShowDialog();
                            this.SavePic();

                        }

                            /*
                            //333,266
                            Rectangle cltrect = ClientRectangle;
                            Point loc = this.pictureBox1.Location;
                            //100 128
                            Size size=this.pictureBox1.Size;
                            //Point scrol = AutoScrollPosition;

                           // Rectangle realrect = this.pictureBox1.Location;
                           // realrect.X -= scrol.X;
                          //  realrect.Y -= scrol.Y;

                            //240
                            int bot = bmprect.Height;

                            dibhand = img;
                            bmpptr = GlobalLock(dibhand);
                            pixptr = GetPixelInfo(bmpptr);
                            IntPtr hdc = this.pictureBox1.CreateGraphics().GetHdc();
                            SetDIBitsToDevice(hdc, 0, 0, bmprect.Width, bmprect.Height,
                                    0, 0, 0, bmprect.Height, pixptr, bmpptr, 0);
                            //this.pictureBox1.CreateGraphics().ReleaseHdc(hdc);
                           // Image img = (Image)pics[i];
                           // PicForm newpic = new PicForm(img);
                           // newpic.MdiParent = this;
                            //this.pictureBox1.Image = img;
                            int picnum = i + 1;

                           // newpic.Text = "ScanPass" + picnumber.ToString() + "_Pic" + picnum.ToString();
                          //  newpic.Show();
                             */

                        }
                        break;
                    }
            }

            return true;
        }
Esempio n. 2
0
 private void btnCapture_Click(object sender, EventArgs e)
 {
     CaptureImage form = new CaptureImage(this.pictureBox1);
     form.ShowDialog();
 }
Esempio n. 3
0
 private void button1_Click(object sender, EventArgs e)
 {
     CaptureImage form = new CaptureImage(Image.FromFile("c:\\test.jpg"), this.picPic, set);
     form.ShowDialog();
     this.SavePic();
 }