private async Task ProcessSingleRequest(PictureRequest request)
        {
            var bytes = await PictureStorage.GetPictureBytesAsync(request.PictureUri);

            OnBeforeTransferResult(request.PictureUri, request.Target, bytes);
            OnImageReceived?.Invoke(request.Target, bytes);
        }
예제 #2
0
        public Captcha(string key, OnImageReceived ircb)
        {
            Key             = key;
            ImageReceivedCB = ircb;

            WebClient wc = new WebClient();

            wc.DownloadDataCompleted += new DownloadDataCompletedEventHandler(wc_DownloadDataCompleted1);
            wc.DownloadDataAsync(new Uri("http://www.google.com/recaptcha/api/challenge?k=" + Key));
        }
예제 #3
0
 private void OnImageDataReceived(byte senderID, byte[] imageData)
 {
     try {
         string path = $"{WPFHelper.DataPath}current{DateTime.Now.ToString("dd.MM_hh.mm.sss")}.jpg";
         File.WriteAllBytes(path, imageData);
         OnImageReceived?.Invoke(this, path);
     }
     catch (Exception) {
         Debugger.Break();
         //TODO
     }
 }
예제 #4
0
        //------------------------------- helpers --------------------------
        void HandleBlobData(DataBlob packet)
        {
            //int sizeOfBlobs = accumulator.GetSizeOfAllBlobs();
            if (accumulator.Add(packet as DataBlob) == true)
            {
                //int sizeOfBlobs = accumulator.GetSizeOfAllBlobs();
                int    numBlobs = accumulator.BlobCount;
                byte[] bytes    = accumulator.ConvertDatablobsIntoRawData();

                int len = bytes.Length;
                OnImageReceived?.Invoke(bytes, bytes.Length);

                accumulator.Clear();
                Console.Write("Blobs received in acc {0}\n", numBlobs);
                Console.Write("Bytes received in blob {0}\n", len);
            }
            return;
        }
예제 #5
0
 private void WatchForImages()
 {
     try
     {
         while (true)
         {
             if (ClientInterface.Connections["ImageReceiver"].DataAvailable)
             {
                 OnImageReceived?.BeginInvoke(ClientInterface.Connections["ImageReceiver"].Reader.ReadBytes(ClientInterface.Connections["ImageReceiver"].Reader.ReadInt32()), result => { try { OnImageReceived.EndInvoke(result); } catch { } }, null);
             }
             else
             {
                 Thread.Sleep(0);
             }
         }
     }
     catch (ThreadInterruptedException) { }
 }
예제 #6
0
        //------------------------------- helpers --------------------------
        void HandleBlobData(DataBlob packet)
        {
            //int sizeOfBlobs = accumulator.GetSizeOfAllBlobs();
            if (accumulator.Add(packet as DataBlob) == true)
            {
                //int sizeOfBlobs = accumulator.GetSizeOfAllBlobs();
                int    numBlobs = accumulator.BlobCount;
                byte[] bytes    = accumulator.ConvertDatablobsIntoRawData();

                int len = bytes.Length;
                OnImageReceived?.Invoke(bytes, bytes.Length);

                accumulator.Clear();
                Console.Write("Blobs received in acc {0}\n", numBlobs);
                Console.Write("Bytes received in blob {0}\n", len);
                var Timestamp = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds();
                Console.WriteLine("request roundtrip total time {0} ms", Timestamp - startTimeMilliseconds);
            }
            return;
        }
        private async Task GetCapturedImage(JsonObject data)
        {
            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
            {
                byte[] buffer     = Convert.FromBase64String(data.GetNamedString("ImageBase64"));
                BitmapImage image = new BitmapImage();
                using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream())
                {
                    await stream.WriteAsync(buffer.AsBuffer());
                    stream.Seek(0);
                    await image.SetSourceAsync(stream);
                }

                currentImage = image;
                while (images.Count >= ImageCacheSize)
                {
                    images.RemoveAt(ImageCacheSize - 1);
                }
                images.Insert(0, image);
                OnImageReceived?.Invoke(this, currentImage);
            });
        }
예제 #8
0
        public async Task CameraFeedAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            //get camera images
            var cameraFeed = Client.CameraFeed(new CameraFeedRequest());

            while (await cameraFeed.ResponseStream.MoveNext(cancellationToken))
            {
                var response = cameraFeed.ResponseStream.Current;
                if (response.Data != null && !response.Data.IsEmpty)
                {
                    //convert to image
                    Image image = null;
                    using (var stream = new MemoryStream(response.Data.ToByteArray()))
                        image = Image.FromStream(stream);

                    //send event
                    OnImageReceived?.Invoke(this, new RobotImageEventArgs()
                    {
                        Image = image
                    });
                }
            }
        }