Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to develop a desktop application from which image can be scanned if scanner is connected with the pc and that will display in the picturebox control.

using WIA dll i am able to scan image from an external device(scanner) but it automatically saves default picture folder.
Can anyone please guide me how to save the picture as per my choice and display that image in a picturebox.

Thanks in advance.
Posted
Updated 30-Nov-12 0:48am
v2

Please have a look here,http://channel9.msdn.com/coding4fun/articles/Look-at-me-Windows-Image-Acquisition[^]

that pretty much sums it up
C#
tem item = device.ExecuteCommand(CommandID.wiaCommandTakePicture);
foreach (string format in item.Formats)
{
    if (format == jpegGuid)
    {
        WIA.ImageFile imagefile = item.Transfer(format) as WIA.ImageFile;
        filename = GetFreeFileName();
        if (string.IsNullOrEmpty(filename) == false)
        {
//Instead of saving  get it to the picture box (you should know how to convert it to Image object
            imagefile.SaveFile(filename);
        }
        this.picLastImage.Load(filename);
        return filename;
    }
}
 
Share this answer
 
v2
Comments
sahabiswarup 30-Nov-12 7:51am    
great resource...let see what i can do ...
sahabiswarup 30-Nov-12 7:58am    
getting this following error

Interop type 'WIA.CommandID' cannot be embedded. Use the applicable interface instead.
and 'WIA.CommandID' does not contain a definition for 'wiaCommandTakePicture'

on this line
CommandID.wiaCommandTakePicture

can you please sort this out?
private void button2_Click(object sender, EventArgs e)
{
    const string wiaFormatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}";
    CommonDialogClass wiaDiag = new CommonDialogClass();
    WIA.ImageFile wiaImage = null;

    wiaImage = wiaDiag.ShowAcquireImage(
            WiaDeviceType.UnspecifiedDeviceType,
            WiaImageIntent.GrayscaleIntent,
            WiaImageBias.MaximizeQuality,
            wiaFormatJPEG, true, true, false);

    WIA.Vector vector = wiaImage.FileData;

    Image i = Image.FromStream(new MemoryStream((byte[])vector.get_BinaryData()));
    i.Save(@"D:\prueba1.jpeg");
}


Final solution works perfectly.
 
Share this answer
 

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