Click or drag to resize

MemoryDataTransferEventArgsOutputStream Property

Gets or sets a Stream to use for saving the image data.

If this property is set to a Stream with write access, DotTwain will write the image data into the stream instead of holding it in memory. No Bitmap object will be created when an OutputStream is provided. See the remarks below for more information.

Namespace:  Atalasoft.Twain
Assembly:  Atalasoft.DotTwain (in Atalasoft.DotTwain.dll) Version: 11.4.0.9.0.377 (.NET 4.5.2, x86)
Syntax
public Stream OutputStream { get; set; }

Property Value

Type: Stream
A Stream to use for saving the data.
Remarks

Normally the MemoryDataTransfer event is raised with each buffer of information retrieved from the device. If the OutputStream property is set, DotTwain will stop raising the event during the transfer and write all data into the stream. Once all data for the image has been received, the MemoryDataTransfer event will be raised again with the MemoryDataTransferEventArgs.Data property set to IntPtr.Zero to allow the Stream to be closed or processed.

The Stream is also provided in the AcquireEventArgs of the ImageAcquired event.

Examples
void _acquisition_MemoryDataTransfer(object sender, MemoryDataTransferEventArgs e)
{
    if (e.Data == IntPtr.Zero)
    {
        // The image is finished. Process as needed.
        e.OutputStream.Close();
        File.Delete(_tempFileName);
    }

    // This will save the raw image data to a file instead of keeping it in memory.
    _tempFileName = Path.GetTempFileName();
    e.OutputStream = new FileStream(_tempFileName, FileMode.Create, FileAccess.Write);
}
See Also