Exemplo n.º 1
0
        /// <summary>
        /// Calls the Start remote procedure (maybe many times) and gets hold
        /// of the scanned image
        /// </summary>
        /// <param name="handle">The handle to the device</param>
        /// <param name="userName">The user name</param>
        /// <param name="password">The password</param>
        /// <param name="cancelToken">The cancellation token</param>
        /// <returns>The scanned image</returns>
        internal BitmapSource Scan(int handle,
                                   string userName,
                                   string password,
                                   CancellationToken cancelToken)
        {
            cancelToken.Register(() => Cancel(handle));

            int  pixelsPerLine;
            int  lines;
            int  depth;
            bool littleEndian;
            bool color;

            byte[] data;
            using (var ms = new MemoryStream())
            {
                int bytesPerLine;
                using (var stream = DoScan(handle,
                                           userName,
                                           password,
                                           true,
                                           ms,
                                           cancelToken,
                                           out bytesPerLine,
                                           out pixelsPerLine,
                                           out lines,
                                           out depth,
                                           out littleEndian,
                                           out color))
                {
                    data = stream.ToArray();
                }
            }

            var ret = ImageCreator.ToBitmap(data,
                                            pixelsPerLine,
                                            lines,
                                            depth,
                                            littleEndian,
                                            color);

            return(ret);
        }