Reputation: 131
I am trying WIA
to acquire images from a scanner with C#. I am using a PictureBox
to acquire images. I am able to scan images. But size of image is too large. How i can set resolution of the image and show this image to Fixed size that can be fit within the form. Where Form WindowState is Maximum.
I am using this code on Button Click to get image from Scanner.
try
{
//get list of devices available
List<string> devices = WIAScanner.GetDevices();
foreach (string device in devices)
{
lbDevices.Items.Add(device);
}
//check if device is not available
if (lbDevices.Items.Count == 0)
{
MessageBox.Show("Attach a Scanner Device.");
}
else
{
lbDevices.SelectedIndex = 0
}
//get images from scanner
List<Image> images = WIAScanner.Scan((string)lbDevices.SelectedItem);
foreach (Image image in images)
{
pic_scan.Image = image;
pic_scan.Show();
pic_scan.SizeMode = PictureBoxSizeMode.AutoSize;
//save scanned image into specific folder
image.Save(@"D:\ABC.jpeg", ImageFormat.Jpeg);
}
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
}
Thanks for kind response.
Upvotes: 0
Views: 585
Reputation: 106
Use PictureBoxSizeMode.Zoom to have the image fit properly in a PictureBox.
pic_scan.SizeMode = PictureBoxSizeMode.Zoom;
Upvotes: 1