Beispiel #1
0
        private ImageSource GenerateThumbnail(DataTransferredEventArgs e)
        {
            BitmapSource image = null;

            switch (e.TransferType)
            {
            case XferMech.Native:
                using (var stream = e.GetNativeImageStream())
                {
                    if (stream != null)
                    {
                        image = stream.ConvertToWpfBitmap(300, 0);
                    }
                }
                break;

            case XferMech.File:
                image = new BitmapImage(new Uri(e.FileDataPath));
                if (image.CanFreeze)
                {
                    image.Freeze();
                }
                break;

            case XferMech.Memory:
                break;
            }

            return(image);
        }
Beispiel #2
0
        ImageSource GenerateThumbnail(DataTransferredEventArgs e)
        {
            BitmapSource img = null;

            switch (e.TransferType)
            {
            case XferMech.Native:
                using (var stream = e.GetNativeImageStream())
                {
                    if (stream != null)
                    {
                        // file size
                        img = stream.ConvertToWpfBitmap();
                    }
                }
                break;

            case XferMech.File:
                img = new BitmapImage(new Uri(e.FileDataPath));
                if (img.CanFreeze)
                {
                    img.Freeze();
                }
                break;

            case XferMech.Memory:
                // TODO: build current image from multiple data-xferred event
                break;
            }
            return(img);
        }
 private void OnDataTransferred(object sender, DataTransferredEventArgs e)
 {
     using (var output = Image.FromStream(e.GetNativeImageStream()))
     {
         _image = new Bitmap(output);
     }
 }
Beispiel #4
0
        private void Session_DataTransferred(object sender, DataTransferredEventArgs e)
        {
            ImageSource image = GenerateThumbnail(e);

            if (image != null)
            {
                System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    CapturedImages.Add(image);
                }));
            }
        }
Beispiel #5
0
        void Session_DataTransferred(object sender, DataTransferredEventArgs e)
        {
            ImageSource img = GenerateThumbnail(e);

            if (img != null)
            {
                App.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    CapturedImages.Add(img);
                    SelectedImage = img;
                    ScannedDocument.UploadQueue.Add(img);
                }));
            }
        }
Beispiel #6
0
        void session_DataTransferred(object sender, DataTransferredEventArgs e)
        {
            theImage = null;
            Stream s   = e.GetNativeImageStream();
            int    len = (int)s.Length;

            byte[] buffer = new byte[len];
            s.Read(buffer, 0, len);
            s.Close();
            MemoryStream ms = new MemoryStream(buffer);

            theImage          = (Bitmap)Image.FromStream(ms);
            pictureBox1.Image = theImage;
        }
Beispiel #7
0
        void _session_DataTransferred(object sender, DataTransferredEventArgs e)
        {
            BitmapSource img = GenerateThumbnail(e);

            if (img != null)
            {
                App.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    CapturedImages.Add(img);
                }));

                //
            }
        }
Beispiel #8
0
        static void DoImageXferredEventRoutine(ITwainSessionInternal session, IntPtr dataPtr, TWImageMemXfer memInfo, byte[] memData, string filePath, FileFormat format)
        {
            DataTransferredEventArgs args = null;

            if (dataPtr != IntPtr.Zero)
            {
                args = new DataTransferredEventArgs(session.CurrentSource, dataPtr);
            }
            else if (memData != null)
            {
                args = new DataTransferredEventArgs(session.CurrentSource, memInfo, memData);
            }
            else
            {
                args = new DataTransferredEventArgs(session.CurrentSource, filePath, format);
            }
            session.SafeSyncableRaiseEvent(args);
        }
Beispiel #9
0
        BitmapSource GenerateThumbnail(DataTransferredEventArgs e)
        {
            BitmapSource img = null;

            switch (e.TransferType)
            {
            case XferMech.Native:
                using (var stream = e.GetNativeImageStream())
                {
                    if (stream != null)
                    {
                        img = stream.ConvertToWpfBitmap(0, 0);
                    }
                }
                break;

            case XferMech.File:
                img = new BitmapImage(new Uri(e.FileDataPath));
                if (img.CanFreeze)
                {
                    img.Freeze();
                }
                break;

            case XferMech.Memory:
                // TODO: build current image from multiple data-xferred event
                break;
            }

            //if (img != null)
            //{
            //    // from http://stackoverflow.com/questions/18189501/create-thumbnail-image-directly-from-header-less-image-byte-array
            //    var scale = MaxThumbnailSize / img.PixelWidth;
            //    var transform = new ScaleTransform(scale, scale);
            //    var thumbnail = new TransformedBitmap(img, transform);
            //    img = new WriteableBitmap(new TransformedBitmap(img, transform));
            //    img.Freeze();
            //}
            return(img);
        }
Beispiel #10
0
 private static void DataTransferred(object sender, DataTransferredEventArgs e)
 {
     if (e.NativeData != IntPtr.Zero)
     {
         Console.WriteLine("SUCCESS! Got twain data on thread {0}.", Thread.CurrentThread.ManagedThreadId);
         var stream = e.GetNativeImageStream();
         if (stream != null)
         {
             byte[] bytes;
             using (var ms = new System.IO.MemoryStream())
             {
                 stream.CopyTo(ms);
                 bytes = ms.ToArray();
             }
             string base64 = Convert.ToBase64String(bytes);
             _socket.Send($"data:image/jpeg;base64,{base64}");
         }
     }
     else
     {
         Console.WriteLine("FAILURE! No twain data on thread {0}.", Thread.CurrentThread.ManagedThreadId);
     }
 }
Beispiel #11
0
 private void SharpDataTransferred(object sender, DataTransferredEventArgs e)
 {
     Log(string.Format("{0} {1}", e.Sent ? "> " : "< ", e.Message));
 }
Beispiel #12
0
        private void Session_DataTransferred(object sender, DataTransferredEventArgs e)
        {
            Image img = Image.FromStream(e.GetNativeImageStream());

            images.Add(img);
        }
Beispiel #13
0
 void SharpDataTransferred(object sender, DataTransferredEventArgs e)
 {
     logTextBox.AppendText(string.Format("{0} {1} \r\n", e.Sent ? "> " : "< ", e.Message));
 }