using NTwain.Data; using System; using System.Collections.Generic; using System.Linq; namespace NTwain { /// /// Contains event data after whatever data from the source has been transferred. /// public class DataTransferredEventArgs : EventArgs { /// /// Initializes a new instance of the class. /// /// The source. /// The native data. /// The image information. public DataTransferredEventArgs(DataSource source, IntPtr nativeData, TWImageInfo imageInfo) { DataSource = source; NativeData = nativeData; ImageInfo = imageInfo; } /// /// Initializes a new instance of the class. /// /// The source. /// The file data path. /// The image information. public DataTransferredEventArgs(DataSource source, string fileDataPath, TWImageInfo imageInfo) { DataSource = source; FileDataPath = fileDataPath; ImageInfo = imageInfo; } /// /// Initializes a new instance of the class. /// /// The source. /// The memory data. /// The image information. public DataTransferredEventArgs(DataSource source, byte[] memoryData, TWImageInfo imageInfo) { DataSource = source; MemoryData = memoryData; ImageInfo = imageInfo; } /// /// Gets pointer to the complete data if the transfer was native. /// The data will be freed once the event handler ends /// so consumers must complete whatever processing before then. /// For image type this data is DIB (Windows) or TIFF (Linux). /// This pointer is already locked for the duration of this event. /// /// The data pointer. public IntPtr NativeData { get; private set; } /// /// Gets the file path to the complete data if the transfer was file or memory-file. /// /// /// The file path. /// public string FileDataPath { get; private set; } /// /// Gets the raw memory data if the transfer was memory. /// Consumer application will need to do the parsing based on the values /// from . /// /// /// The memory data. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] public byte[] MemoryData { get; private set; } /// /// Gets the final image information if applicable. /// /// /// The final image information. /// public TWImageInfo ImageInfo { get; private set; } /// /// Gets the data source. /// /// /// The data source. /// public DataSource DataSource { get; private set; } /// /// Gets the extended image information if applicable. /// /// The information ids. /// /// public IEnumerable GetExtImageInfo(params ExtendedImageInfo[] infoIds) { if (infoIds != null && infoIds.Length > 0 && DataSource.SupportedCaps.Contains(CapabilityId.ICapExtImageInfo)) { var request = new TWExtImageInfo { NumInfos = (uint)infoIds.Length }; if (infoIds.Length > request.Info.Length) { throw new InvalidOperationException(string.Format("Info ID array excdd maximum length of {0}.", request.Info.Length)); } for (int i = 0; i < infoIds.Length; i++) { request.Info[i].InfoID = infoIds[i]; } if (DataSource.DGImage.ExtImageInfo.Get(request) == ReturnCode.Success) { return request.Info.Where(it => it.InfoID != ExtendedImageInfo.Invalid); } } return Enumerable.Empty(); } } }