예제 #1
0
        private void OnGetPictures(object sender, ExecutedRoutedEventArgs e)
        {
            int pics = int.Parse(numPictures.Text);

            for (int i = 0; i < pics; i++)
            {
                WebRequest req = WebRequest.Create("http://localhost:9000/pictures/picture");

                WebResponse resp = req.GetResponse();

                PictureItem item = new PictureItem();

                BitmapImage bmp = new BitmapImage();

                bmp.DownloadCompleted += delegate
                {
                    resp.Close();
                };

                bmp.BeginInit();
                bmp.StreamSource = resp.GetResponseStream();
                bmp.EndInit();

                item.Source = bmp;

                double left = rnd.NextDouble() * board.ActualWidth;
                double top  = rnd.NextDouble() * board.ActualHeight;
                Canvas.SetLeft(item, left);
                Canvas.SetTop(item, top);

                item.Angle = rnd.Next(-45, 45);

                board.Children.Add(item);
            }
        }
예제 #2
0
        void UpdateUI(Task <WebResponse> t)
        {
            PictureItem item = new PictureItem();

            BitmapImage bmp = new BitmapImage();

            bmp.DownloadCompleted += delegate
            {
                t.Result.Close();
            };

            bmp.BeginInit();
            bmp.StreamSource = t.Result.GetResponseStream();
            bmp.EndInit();

            item.Source = bmp;

            double left = rnd.NextDouble() * board.ActualWidth;
            double top  = rnd.NextDouble() * board.ActualHeight;

            Canvas.SetLeft(item, left);
            Canvas.SetTop(item, top);

            item.Angle = rnd.Next(-45, 45);

            board.Children.Add(item);
        }