Click here to Skip to main content
15,915,509 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

I have done code for scanning and it work fine when we put single document on scanner.If we put multiple document so how we do that it scan automatically all? My code is

C#
// Scanner selected?
           var device = Devices.SelectedItem as Scanner;
           if (device == null)
           {
               MessageBox.Show("Please select a device.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
               return;
           }
           // Scan
           var images = device.Scan();
           //Save the image
           strFinalImagename = txtPolicyno.Text + "_" + ddlDept.SelectedItem + "." + ddlFormat.SelectedItem;

           string strImagename = "test.jpg";
           string path = System.Configuration.ConfigurationSettings.AppSettings["Path"] + strImagename;
           if (File.Exists(path))
           {
               File.Delete(path);
           }
           System.IO.Directory.CreateDirectory(System.Configuration.ConfigurationSettings.AppSettings["Path"]);

           images.SaveFile(path);

           string ImageText = txtPolicyno.Text + "_" + ddlDept.SelectedItem;

           //System.Drawing.Bitmap bitMapImage = new System.Drawing.Bitmap(path);
           //System.Drawing.Graphics graphicImage = System.Drawing.Graphics.FromImage(bitMapImage);
           //graphicImage.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
           //graphicImage.DrawArc(new System.Drawing.Pen(System.Drawing.Color.White, 3), 90, 235, 150, 50, 0, 360);
           //graphicImage.DrawString(ImageText, new System.Drawing.Font("Arial", 15, System.Drawing.FontStyle.Regular), System.Drawing.SystemBrushes.WindowText, new System.Drawing.Point(550, 20));

           ////bitMapImage.Save(@"D:\" + strFinalImagename, System.Drawing.Imaging.ImageFormat.Jpeg);
           //bitMapImage.Save(System.Configuration.ConfigurationSettings.AppSettings["Path"] + strFinalImagename, System.Drawing.Imaging.ImageFormat.Jpeg);
           //graphicImage.Dispose();
           //bitMapImage.Dispose();

           using (var src = new System.Drawing.Bitmap(path))
           using (var bmp = new System.Drawing.Bitmap(1000, 1000, System.Drawing.Imaging.PixelFormat.Format32bppPArgb))
           using (var gr = System.Drawing.Graphics.FromImage(bmp))
           {
               gr.Clear(System.Drawing.Color.Blue);
               gr.DrawImage(src, new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height));
               gr.DrawString(ImageText, new System.Drawing.Font("Arial", 15, System.Drawing.FontStyle.Regular), System.Drawing.SystemBrushes.WindowText, new System.Drawing.Point(550, 20));
               bmp.Save(System.Configuration.ConfigurationSettings.AppSettings["Path"] + strFinalImagename, System.Drawing.Imaging.ImageFormat.Png);
           }
Posted
Comments
gggustafson 2-Apr-14 11:25am    
I cannot tell if you are using TWAIN.

Have you read the TWAIN specification at www.twain.org? I do not see the code necessary to check for a document feeder nor do I see any code that would loop over the images. The specification states

Transferring multiple images simply requires looping through the single-image
transfer process repeatedly whenever more images are available

There also appear to be some problems with your code. I would suggest that you prune everything that is not absolutely necessary to perform your task. Get rid of all comments; rename variables to be meaningful; indent your code; etc.

Also see http://www.codeproject.com/Articles/1376/NET-TWAIN-image-scanner.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900