private void AcquireBuffered_Click(object sender, EventArgs e) { if (SelectedSource != 0) { TwainAPI.DTWAIN_SetBlankPageDetection(SelectedSource, 98.5, (int)TwainAPI.DTWAIN_BP_AUTODISCARD_ANY, DiscardBlankPages.Checked ? 1 : 0); DTWAIN_ARRAY acquireArray = TwainAPI.DTWAIN_CreateAcquisitionArray(); this.Enabled = false; int status = 0; if (TwainAPI.DTWAIN_AcquireBufferedEx(SelectedSource, TwainAPI.DTWAIN_PT_DEFAULT, TwainAPI.DTWAIN_ACQUIREALL, UseSourceUI.Checked ? 1 : 0, 0, acquireArray, ref status) == 0) { MessageBox.Show("Acquisition Failed", "TWAIN Error"); return; } if (TwainAPI.DTWAIN_ArrayGetCount(acquireArray) == 0) { MessageBox.Show("No Images Acquired", ""); return; } // Display the DIBS //... DIBDisplayerDlg sDIBDlg = new DIBDisplayerDlg(acquireArray); sDIBDlg.ShowDialog(); TwainAPI.DTWAIN_DestroyAcquisitionArray(acquireArray, 0); this.Enabled = true; } }
private void LoggingOptions_Click(object sender, EventArgs e) { long LogFlags = TwainAPI.DTWAIN_LOG_ALL & ~TwainAPI.DTWAIN_LOG_ERRORMSGBOX; LogFileSelectionDlg logDlg = new LogFileSelectionDlg(); DialogResult nResult = logDlg.ShowDialog(); if (nResult == DialogResult.OK) { int debugOption = logDlg.GetDebugOption(); switch (debugOption) { case 0: break; case 1: TwainAPI.DTWAIN_SetTwainLog(0, ""); break; case 2: TwainAPI.DTWAIN_SetTwainLog((int)(LogFlags | TwainAPI.DTWAIN_LOG_USEFILE), logDlg.GetFileName()); break; case 3: TwainAPI.DTWAIN_SetTwainLog((int)(LogFlags & ~TwainAPI.DTWAIN_LOG_USEFILE), ""); MessageBox.Show("The DebugView debug monitor will start..."); Process.Start("DbgView.exe"); break; } } }
private void CustomSelectSource_Load(object sender, EventArgs e) { sourceSelected = false; DTWAIN_ARRAY SourceArray = 0; TwainAPI.DTWAIN_EnumSources(ref SourceArray); int nCount = TwainAPI.DTWAIN_ArrayGetCount(SourceArray); if (nCount <= 0) { Close(); } // Display the sources DTWAIN_SOURCE CurSource = 0; for (int i = 0; i < nCount; ++i) { StringBuilder szName = new StringBuilder(256); TwainAPI.DTWAIN_ArrayGetAtLong(SourceArray, i, ref CurSource); TwainAPI.DTWAIN_GetSourceProductName(CurSource, szName, 255); listSources.Items.Add(szName.ToString()); } listSources.SelectedIndex = 0; // Display Info about sources string sText = nCount.ToString() + " TWAIN Source(s) Available for Selection"; editSourceInfo.Text = sText; }
private void AboutDlg_Load(object sender, EventArgs e) { int nChars = TwainAPI.DTWAIN_GetVersionInfo(IntPtr.Zero, -1); StringBuilder szInfo = new StringBuilder(nChars); TwainAPI.DTWAIN_GetVersionInfo(szInfo, nChars); edInfo.Text = szInfo.ToString(); }
// Displays the DIB bitmap for acquisition nCurrentAcquisition, page nCurDib private void DisplayTheDib() { int dib = TwainAPI.DTWAIN_GetAcquiredImage(AcquireArray, nCurrentAcquisition, nCurDib); IntPtr dibPtr = GlobalLock(dib); this.dibBox.Image = BitmapFromDIB(dibPtr); GlobalUnlock(dibPtr); EnablePageButtons(); }
private void CloseSource_Click(object sender, EventArgs e) { if (SelectedSource != 0) { TwainAPI.DTWAIN_CloseSource(SelectedSource); SelectedSource = 0; SetCaptionToSourceName(); EnableSourceItems(false); } }
/// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose(bool disposing) { TwainAPI.DTWAIN_SysDestroy(); if (disposing) { if (components != null) { components.Dispose(); } } base.Dispose(disposing); }
private void DIBDisplayerDlg_Load(object sender, EventArgs e) { // Set up acquisition combo box nCurrentAcquisition = 0; nCurDib = 0; int nCount = TwainAPI.DTWAIN_GetNumAcquisitions(AcquireArray); for (int i = 1; i <= nCount; ++i) { this.cmbAcquisition.Items.Add(i.ToString()); } this.cmbAcquisition.SelectedIndex = 0; // Display the bitmap DisplayTheDib(); }
private void EnablePageButtons() { int nCount = TwainAPI.DTWAIN_GetNumAcquiredImages(AcquireArray, nCurrentAcquisition); this.buttonNext.Enabled = (nCurDib < nCount - 1); this.buttonPrev.Enabled = (nCurDib > 0); if (nCount == 0) { } else { int sDib = nCurDib + 1; this.edPageCurrent.Text = sDib.ToString(); this.edPageTotal.Text = nCount.ToString(); } }
private void SetCaptionToSourceName() { StringBuilder szSourceName = new StringBuilder(256); string sTitle = sOrigTitle; if (SelectedSource != 0) { TwainAPI.DTWAIN_GetSourceProductName(SelectedSource, szSourceName, 255); sTitle += " - "; sTitle += szSourceName; this.Text = sTitle; } else { this.Text = sOrigTitle; } }
public DTwainDemo() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // sOrigTitle = this.Text; TwainAPI.DTWAIN_SysInitialize(); SelectedSource = 0; if (TwainAPI.DTWAIN_IsTwainAvailable() == 0) { SelectSource.Enabled = false; SelectSourceByNameBox.Enabled = false; } }
private void SourcePropertiesDlg_Load(object sender, EventArgs e) { StringBuilder szInfo = new StringBuilder(256); TwainAPI.DTWAIN_GetSourceProductName(m_Source, szInfo, 255); this.edProductName.Text = szInfo.ToString(); TwainAPI.DTWAIN_GetSourceProductFamily(m_Source, szInfo, 255); this.edFamilyName.Text = szInfo.ToString(); TwainAPI.DTWAIN_GetSourceManufacturer(m_Source, szInfo, 255); this.edManufacturer.Text = szInfo.ToString(); TwainAPI.DTWAIN_GetSourceVersionInfo(m_Source, szInfo, 255); this.edVersionInfo.Text = szInfo.ToString(); int lMajor = 0, lMinor = 0; TwainAPI.DTWAIN_GetSourceVersionNumber(m_Source, ref lMajor, ref lMinor); string sVersion = lMajor.ToString() + "." + lMinor.ToString(); this.edVersion.Text = sVersion; DTWAIN_ARRAY AllCaps = 0; int Val = 0; TwainAPI.DTWAIN_EnumSupportedCaps(m_Source, ref AllCaps); int nSize = TwainAPI.DTWAIN_ArrayGetCount(AllCaps); for (int i = 0; i < nSize; ++i) { // get the cap value TwainAPI.DTWAIN_ArrayGetAtLong(AllCaps, i, ref Val); // get the name from the cap TwainAPI.DTWAIN_GetNameFromCap(Val, szInfo, 255); this.listCaps.Items.Add(szInfo.ToString()); } this.edTotalCaps.Text = nSize.ToString(); TwainAPI.DTWAIN_EnumCustomCaps(m_Source, ref AllCaps); this.edCustomCaps.Text = TwainAPI.DTWAIN_ArrayGetCount(AllCaps).ToString(); TwainAPI.DTWAIN_EnumExtendedCaps(m_Source, ref AllCaps); this.edExtendedCaps.Text = TwainAPI.DTWAIN_ArrayGetCount(AllCaps).ToString(); }
private void AcquireToFile(int nWhich) { if (SelectedSource != 0) { int status = 0; int bError = 0; long FileFlags = 0; string tFileName = ""; int fileType = 0; switch (nWhich) { case 0: FileFlags = TwainAPI.DTWAIN_USELONGNAME | TwainAPI.DTWAIN_USENATIVE; TwainAPI.DTWAIN_SetBlankPageDetection(SelectedSource, 98.5, (int)TwainAPI.DTWAIN_BP_AUTODISCARD_ANY, DiscardBlankPages.Checked ? 1 : 0); FileTypeDlg fDlg = new FileTypeDlg(); fDlg.ShowDialog(); tFileName = fDlg.GetFileName(); StringBuilder szSourceName = new StringBuilder(tFileName); fileType = fDlg.GetFileType(); break; case 1: if (TwainAPI.DTWAIN_IsFileXferSupported(SelectedSource, TwainAPI.DTWAIN_ANYSUPPORT) == 0) { MessageBox.Show("Sorry. The selected driver does not have built-in file transfer support."); return; } if (TwainAPI.DTWAIN_IsFileXferSupported(SelectedSource, TwainAPI.DTWAIN_FF_BMP) == 0) { string sText = "Sorry. This demo program only supports built-in BMP file transfers.\r\n"; sText += "However, the DTWAIN library will support all built-in formats if your driver\r\n"; sText += "supports other formats."; MessageBox.Show(sText); return; } FileFlags = TwainAPI.DTWAIN_USESOURCEMODE | TwainAPI.DTWAIN_USELONGNAME; fileType = TwainAPI.DTWAIN_FF_BMP; tFileName = ".\\IMAGE.BMP"; MessageBox.Show("The name of the image file that will be saved is IMAGE.BMP\n"); break; } bError = TwainAPI.DTWAIN_AcquireFile(SelectedSource, tFileName, fileType, (int)FileFlags, TwainAPI.DTWAIN_PT_DEFAULT, /* Use default */ TwainAPI.DTWAIN_ACQUIREALL, /* Get all pages */ UseSourceUI.Checked ? 1 : 0, 1, /* Close Source when UI is closed */ ref status ); if (bError == 0) { MessageBox.Show("Error acquiring or saving file."); } else if (status == TwainAPI.DTWAIN_TN_ACQUIREDONE) { MessageBox.Show("Image file saved successfully"); } else { MessageBox.Show("The acquisition returned a status of " + status.ToString()); } } }
private void SelectTheSource(int nWhich) { if (SelectedSource != 0) { DialogResult nReturn; nReturn = MessageBox.Show("For this demo, only one Source can be opened. Close current Source?", "DTWAIN Message", MessageBoxButtons.YesNo); if (nReturn == DialogResult.Yes) { TwainAPI.DTWAIN_CloseSource(SelectedSource); SelectedSource = 0; // EnableSourceItems( FALSE ); } else { return; } } this.Enabled = false; // disable the main form switch (nWhich) { case 0: // Select the source SelectedSource = TwainAPI.DTWAIN_SelectSource(); break; case 1: SelectSourceByNameBox objSelectSourceByName = new SelectSourceByNameBox(); DialogResult nResult = objSelectSourceByName.ShowDialog(); if (nResult == DialogResult.OK) { SelectedSource = TwainAPI.DTWAIN_SelectSourceByName(objSelectSourceByName.GetText()); } break; case 2: SelectedSource = TwainAPI.DTWAIN_SelectDefaultSource(); break; case 3: CustomSelectSource customSourceDlg = new CustomSelectSource(); DialogResult dResult = customSourceDlg.ShowDialog(); if (dResult == DialogResult.OK) { SelectedSource = TwainAPI.DTWAIN_SelectSourceByName(customSourceDlg.GetSourceName()); } break; } this.Enabled = true; // re-enable the main form if (SelectedSource != 0) { if (TwainAPI.DTWAIN_OpenSource(SelectedSource) != 0) { TwainAPI.DTWAIN_EnableFeeder(SelectedSource, 1); SetCaptionToSourceName(); EnableSourceItems(true); return; } else { MessageBox.Show("Error Opening Source", "TWAIN Error", MessageBoxButtons.OK); } } else { MessageBox.Show("Error Selecting Source", "TWAIN Error", MessageBoxButtons.OK); } EnableSourceItems(false); }