locked
windows image acquisition RRS feed

  • Question

  • I am developing application using c# i want to make a scanner application so I am using WIA component for that. Now I am getting image like Image 1 I want to display it like image 2 

    Here is the code I am using

    public static System.Drawing.Image GetScannedImage()
           {
               System.Drawing.Image scannedImage = null;
               try
               {
                   WIA.CommonDialog wiaDiag = new WIA.CommonDialog();
                   WIA.Device _scanner = wiaDiag.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, false, false);
                   foreach (Property item in _scanner.Items[1].Properties)
                   {
                       System.Windows.Forms.MessageBox.Show("Property name  : " + item.Name + "\n Property id  : " + item.PropertyID + " \nProperty value  : " + item.get_Value());

                       switch (item.PropertyID)
                       {
                           case 4103: //Datatype color 3
                               SetProperty(item, 3);
                               break;
                          /* case 6147:
                               SetProperty(item, 600);
                               break;
                           case 6148:
                               SetProperty(item, 600);
                               break;*/

                       }
                   }
                   WIA.ImageFile wiaImage = (WIA.ImageFile)_scanner.Items[1].Transfer(FormatID.wiaFormatJPEG);
                   WIA.Vector vector = wiaImage.FileData;
                   System.Drawing.Image ImageFromScaner = System.Drawing.Image.FromStream(new MemoryStream((byte[])vector.get_BinaryData()));

                   
                  
                  // System.Drawing.Image AutoCroppedScandeImage = ImageUtilitiesEx.AforgeAutoCrop((Bitmap)ImageFromScaner);
                  
                  
                   System.Drawing.Image AutoCroppedScandeImage = ImageUtilitiesEx.AforgeAutoCrop((Bitmap)ImageFromScaner);
                   System.Drawing.Image AutoSkewedImage = ImageUtilitiesEx.autoSkew((Bitmap)AutoCroppedScandeImage);
                       //scannedImage = AutoSkewedImage;
                   scannedImage = ImageUtilities.resizeImage(RotateImage(ImageUtilitiesEx.AforgeAutoCrop((Bitmap)AutoSkewedImage), -90, Color.Black), new Size(1500, 1500));
                   
                   
                   //Size siz = new Size(2000, 2000);
                       //editedImage = editImage(scanedImage, siz, -90, Color.Transparent,true,documentType);

                       
                       
                  
                   //wiaDiag.ShowAcquireImage(
                   //wiaDiag.ShowAcquireImage(WiaDeviceType.UnspecifiedDeviceType, WiaImageIntent.GrayscaleIntent, WiaImageBias.MaximizeQuality, wiaFormatJPEG, true, true, false);
                   // wiaDiag.ShowItemProperties(_scanner.Items[1], false);
                   // wiaDiag.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, true, false);

               }
               catch (Exception ex)
               {
                   System.Windows.Forms.MessageBox.Show(ex.Message);  
               }
               return (System.Drawing.Image)scannedImage;
           }

    Sunday, August 5, 2012 2:37 PM

Answers

  • Hi RekaShpe,

    Welcome to the MSDN Forum.

    Please take a look at this codeproject: http://www.codeproject.com/Articles/2303/WIA-Scripting-and-NET 

    How to use Windows Image Acquisition on Windows XP. Useful for integrating scanners, digital cameras, webcams and still-video.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, August 6, 2012 9:45 AM
    Moderator