/// <summary> /// Handle an image. a_bitmap is passed by reference so that this function can /// dispose and null it out to gain access to the file that's backing it. The /// calling toolkit function will never perform any action with a_bitmap after /// this function returns. /// </summary> /// <param name="a_szDg">Data group that preceeded this call</param> /// <param name="a_szDat">Data argument type that preceeded this call</param> /// <param name="a_szMsg">Message that preceeded this call</param> /// <param name="a_sts">Current status</param> /// <param name="a_bitmap">C# bitmap of the image</param> /// <param name="a_szFile">File name, if doing a file transfer</param> /// <param name="a_szTwimageinfo">data collected for us</param> /// <param name="a_abImage">a byte array of the image</param> /// <param name="a_iImageOffset">byte offset where the image data begins</param> private TWAINCSToolkit.MSG ReportImage ( string a_szTag, string a_szDg, string a_szDat, string a_szMsg, TWAINCSToolkit.STS a_sts, Bitmap a_bitmap, string a_szFile, string a_szTwimageinfo, byte[] a_abImage, int a_iImageOffset ) { // Let us be called from any thread if (this.InvokeRequired) { // We need a copy of the bitmap, because we're not going to wait // for the thread to return. Be careful when using EndInvoke. // It's possible to create a deadlock situation with the Stop // button press. BeginInvoke(new MethodInvoker(delegate() { ReportImage(a_szTag, a_szDg, a_szDat, a_szMsg, a_sts, a_bitmap, a_szFile, a_szTwimageinfo, a_abImage, a_iImageOffset); })); return(TWAINCSToolkit.MSG.ENDXFER); } if (a_bitmap == null) { // Report errors, but only if the driver's indicators have // been turned off, otherwise we'll hit the user with multiple // dialogs for the same error if (!Settings.Default.ShowDriverMessages && (a_sts != TWAINCSToolkit.STS.SUCCESS)) { HandleError(string.Format("{0}: {1}", Resources.ErrorFromSource, a_sts)); } } else { AddPage(a_bitmap); } return(TWAINCSToolkit.MSG.ENDXFER); }
/// <summary> /// Handle an image. a_bitmap is passed by reference so that this function can /// dispose and null it out to gain access to the file that's backing it. The /// calling toolkit function will never perform any action with a_bitmap after /// this function returns. /// </summary> /// <param name="a_szDg">Data group that preceeded this call</param> /// <param name="a_szDat">Data argument type that preceeded this call</param> /// <param name="a_szMsg">Message that preceeded this call</param> /// <param name="a_sts">Current status</param> /// <param name="a_bitmap">C# bitmap of the image</param> /// <param name="a_szFile">File name, if doing a file transfer</param> /// <param name="a_szTwimageinfo">data collected for us</param> /// <param name="a_abImage">a byte array of the image</param> /// <param name="a_iImageOffset">byte offset where the image data begins</param> public TWAINCSToolkit.MSG ReportImage ( string a_szTag, string a_szDg, string a_szDat, string a_szMsg, TWAINCSToolkit.STS a_sts, Bitmap a_bitmap, string a_szFile, string a_szTwimageinfo, byte[] a_abImage, int a_iImageOffset ) { // We're leaving... if (m_blClosing || (m_graphics1 == null) || (a_bitmap == null)) { return(TWAINCSToolkit.MSG.RESET); } // Let us be called from any thread... if (this.InvokeRequired) { // We need a copy of the bitmap, because we're not going to wait // for the thread to return. Be careful when using EndInvoke. // It's possible to create a deadlock situation with the Stop // button press. BeginInvoke(new MethodInvoker(delegate() { ReportImage(a_szTag, a_szDg, a_szDat, a_szMsg, a_sts, a_bitmap, a_szFile, a_szTwimageinfo, a_abImage, a_iImageOffset); })); return(TWAINCSToolkit.MSG.ENDXFER); } // Display the image... switch (m_iCurrentPictureBox) { default: case 0: LoadImage(ref m_pictureboxImage1, ref m_graphics1, ref m_bitmapGraphic1, a_bitmap); break; case 1: LoadImage(ref m_pictureboxImage2, ref m_graphics2, ref m_bitmapGraphic2, a_bitmap); break; case 2: LoadImage(ref m_pictureboxImage3, ref m_graphics3, ref m_bitmapGraphic3, a_bitmap); break; case 3: LoadImage(ref m_pictureboxImage4, ref m_graphics4, ref m_bitmapGraphic4, a_bitmap); break; case 4: LoadImage(ref m_pictureboxImage5, ref m_graphics5, ref m_bitmapGraphic5, a_bitmap); break; case 5: LoadImage(ref m_pictureboxImage6, ref m_graphics6, ref m_bitmapGraphic6, a_bitmap); break; case 6: LoadImage(ref m_pictureboxImage7, ref m_graphics7, ref m_bitmapGraphic7, a_bitmap); break; case 7: LoadImage(ref m_pictureboxImage8, ref m_graphics8, ref m_bitmapGraphic8, a_bitmap); break; } // Next picture box... if (++m_iCurrentPictureBox >= 8) { m_iCurrentPictureBox = 0; } // All done... return(TWAINCSToolkit.MSG.ENDXFER); }
/// <summary> /// Handle an image. a_bitmap is passed by reference so that this function can /// dispose and null it out to gain access to the file that's backing it. The /// calling toolkit function will never perform any action with a_bitmap after /// this function returns. /// </summary> /// <param name="a_szDg">Data group that preceeded this call</param> /// <param name="a_szDat">Data argument type that preceeded this call</param> /// <param name="a_szMsg">Message that preceeded this call</param> /// <param name="a_sts">Current status</param> /// <param name="a_bitmap">C# bitmap of the image</param> /// <param name="a_szFile">File name, if doing a file transfer</param> /// <param name="a_szTwimageinfo">data collected for us</param> /// <param name="a_abImage">a byte array of the image</param> /// <param name="a_iImageOffset">byte offset where the image data begins</param> private TWAINCSToolkit.MSG ReportImage ( string a_szTag, string a_szDg, string a_szDat, string a_szMsg, TWAINCSToolkit.STS a_sts, Bitmap a_bitmap, string a_szFile, string a_szTwimageinfo, byte[] a_abImage, int a_iImageOffset ) { // We're leaving... if (m_graphics1 == null) { return(TWAINCSToolkit.MSG.RESET); } // Let us be called from any thread... if (this.InvokeRequired) { // We need a copy of the bitmap, because we're not going to wait // for the thread to return. Be careful when using EndInvoke. // It's possible to create a deadlock situation with the Stop // button press. BeginInvoke(new MethodInvoker(delegate() { ReportImage(a_szTag, a_szDg, a_szDat, a_szMsg, a_sts, a_bitmap, a_szFile, a_szTwimageinfo, a_abImage, a_iImageOffset); })); return(TWAINCSToolkit.MSG.ENDXFER); } // We're processing end of scan... if (a_bitmap == null) { // Report errors, but only if the driver's indicators have // been turned off, otherwise we'll hit the user with multiple // dialogs for the same error... if (!m_blIndicators && (a_sts != TWAINCSToolkit.STS.SUCCESS)) { MessageBox.Show("End of session status: " + a_sts); } // Get ready for the next scan... SetButtons(EBUTTONSTATE.OPEN); return(TWAINCSToolkit.MSG.ENDXFER); } // Display the image... if (m_iUseBitmap == 0) { m_iUseBitmap = 1; LoadImage(ref m_pictureboxImage1, ref m_graphics1, ref m_bitmapGraphic1, a_bitmap); } else { m_iUseBitmap = 0; LoadImage(ref m_pictureboxImage2, ref m_graphics2, ref m_bitmapGraphic2, a_bitmap); } // All done... return(TWAINCSToolkit.MSG.ENDXFER); }