Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does my code throw an exception when I try to scan using WIA?
    primarykey
    data
    text
    <p>I'm making an application on C# Winforms which scans documents and places them into a PictureBox, However when I attempt to scan it throws an exception saying "Object Reference not set to an instance of an object" and will not allow me to continue, the stack trace is as below;</p> <p>To clarify, this is a work project in case anyone gets alarmed by some of the class names.</p> <pre><code>AbDesktop.exe!AbDesktop.FrmCreditCards.ScanSetup() Line 39 C# AbDesktop.exe!AbDesktop.FrmCreditCards.ScanFrontBtn_Click(object sender, System.EventArgs e) Line 94 + 0x8 bytes C# [External Code] AbDesktop.exe!AbDesktop.Program.Main(string[] args) Line 26 + 0x20 bytes C# [External Code] </code></pre> <p>this is the code that is causing the issue;</p> <pre><code> public void ScanSetup() { WIA.CommonDialog dialog = new WIA.CommonDialog(); ImageFile scannedImage=null; scannedImage = dialog.ShowAcquireImage( WiaDeviceType.ScannerDeviceType, WiaImageIntent.UnspecifiedIntent, WiaImageBias.MaximizeQuality, FormatID.wiaFormatPNG, true, true, false); scannedImage.SaveFile("C:/Users/reece.cottam/Pictures"); } </code></pre> <p>and this is the button that executes the above code when the click event is fired</p> <pre><code>private void ScanFrontBtn_Click(object sender, EventArgs e) { ScanSetup(); ImageFile IF = new ImageFile(); FrontScanBox.Image = IF.LoadFile("scannedimage.png"); } </code></pre> <p>Any help would be greatly appreciated.</p> <p><em><strong>EDIT</em></strong> The line of code causing the error is ScannedImage.Savefile</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload