View on GitHub

SARAFF SOFTWARE

All products / Saraff.Twain.NET / Contents

Native Mode Transfer

Native mode is the default mode. There is one potential limitation that can occur in a Native mode transfer. That is, there may not be an adequately large block of RAM available to hold the image. Enable native mode transfer as follows:

this._twain32.Capabilities.XferMech.Set(TwSX.Native);

Image transmission is implemented as follows: for each of the received image is raised EndXfer event, and after completion of scanning is raised AcquireCompleted event. In the AcquireCompleted event handler can be used the GetImage method and the ImageCount property for retrieving all scanned images.

private void _twain32_EndXfer(object sender,Twain32.EndXferEventArgs e) {
    try {
        using(var _image = e.Image) {
            _image.Save("filename.tif",ImageFormat.Tiff);
        }
   } catch(Exception ex) {
        MessageBox.Show(ex.Message,ex.GetType().Name,MessageBoxButtons.OK,MessageBoxIcon.Error);
    }
}
private void _twain32_AcquireCompleted(object sender,EventArgs e) {
    try {
        for(int i=0; i<this._twain32.ImageCount; i++) {
            using(var _image=this._twain32.GetImage(i)){
                _image.Save(Path.GetTempFileName());
            }
        }
    } catch(Exception ex) {
        MessageBox.Show(ex.Message,ex.GetType().Name,MessageBoxButtons.OK,MessageBoxIcon.Error);
    }
}