예제 #1
0
        /// <summary>
        /// For the given bitmap renders filtered thumbnails for each filter in given list and populates
        /// the given wrap panel with the them.
        ///
        /// For quick rendering, renders 10 thumbnails synchronously and then releases the calling thread.
        /// </summary>
        /// <param name="bitmap">Source bitmap to be filtered</param>
        /// <param name="side">Side length of square thumbnails to be generated</param>
        /// <param name="list">List of filters to be used, one per each thumbnail to be generated</param>
        /// <param name="panel">Wrap panel to be populated with the generated thumbnails</param>
        private async Task RenderThumbnailsAsync(Bitmap bitmap, int side, List <FilterModel> list, WrapPanel panel)
        {
            using (EditingSession session = new EditingSession(bitmap))
            {
                int i = 0;

                foreach (FilterModel filter in list)
                {
                    WriteableBitmap writeableBitmap = new WriteableBitmap(side, side);

                    foreach (IFilter f in filter.Components)
                    {
                        session.AddFilter(f);
                    }

                    Windows.Foundation.IAsyncAction action = session.RenderToBitmapAsync(writeableBitmap.AsBitmap());

                    i++;

                    if (i % 10 == 0)
                    {
                        // async, give control back to UI before proceeding.
                        await action;
                    }
                    else
                    {
                        // synchroneous, we keep the CPU for ourselves.
                        Task task = action.AsTask();
                        task.Wait();
                    }

                    PhotoThumbnail photoThumbnail = new PhotoThumbnail()
                    {
                        Bitmap = writeableBitmap,
                        Text   = filter.Name,
                        Width  = side,
                        Margin = new Thickness(6)
                    };

                    photoThumbnail.Tap += (object sender, System.Windows.Input.GestureEventArgs e) =>
                    {
                        App.PhotoModel.ApplyFilter(filter);
                        App.PhotoModel.Dirty = true;

                        NavigationService.GoBack();
                    };

                    panel.Children.Add(photoThumbnail);

                    session.UndoAll();
                }
            }
        }
        /// <summary>
        /// For the given bitmap renders filtered thumbnails for each filter in given list and populates
        /// the given wrap panel with the them.
        ///
        /// For quick rendering, renders 10 thumbnails synchronously and then releases the calling thread.
        /// </summary>
        /// <param name="bitmap">Source bitmap to be filtered</param>
        /// <param name="side">Side length of square thumbnails to be generated</param>
        /// <param name="list">List of filters to be used, one per each thumbnail to be generated</param>
        /// <param name="panel">Wrap panel to be populated with the generated thumbnails</param>
        private async Task RenderThumbnailsAsync(Bitmap bitmap, int side, List <FilterModel> list, WrapPanel FiltersWrapPanel)
        {
            using (EditingSession session = new EditingSession(bitmap))
            {
                //render filtered photo
                int i = 0;
                foreach (FilterModel filter in list)
                {
                    WriteableBitmap writeableBitmap = new WriteableBitmap(side, side);

                    //crop the bitmap
                    foreach (IFilter f in filter.Components)
                    {
                        session.AddFilter(f);
                    }

                    Windows.Foundation.IAsyncAction action = session.RenderToBitmapAsync(writeableBitmap.AsBitmap());

                    i++;
                    if (i % 10 == 0)
                    {
                        // async, give control back to UI before proceeding.
                        await action;
                    }
                    else
                    {
                        // synchroneous, we keep the CPU for ourselves.
                        Task task = action.AsTask();
                        task.Wait();
                    }

                    PhotoThumbnail photoThumbnail = new PhotoThumbnail()
                    {
                        Bitmap = writeableBitmap,
                        Text   = filter.Name,
                        Width  = side,
                        Margin = new Thickness(6)
                    };

                    photoThumbnail.Tap += async delegate
                    {
                        ProgressIndicator.IsRunning = true;
                        SetScreenButtonsEnabled(false);

                        App.ThumbnailModel.UndoAllFilters();
                        App.ThumbnailModel.ApplyFilter(filter, _shouldCrop);
                        App.ThumbnailModel.Dirty = true;

                        WriteableBitmap photo = new WriteableBitmap((int)App.ThumbnailModel.Width, (int)App.ThumbnailModel.Height);
                        await App.ThumbnailModel.RenderBitmapAsync(photo);

                        PhotoViewer.Source = photo;

                        SetScreenButtonsEnabled(true);
                        ProgressIndicator.IsRunning = false;
                    };

                    FiltersWrapPanel.Children.Add(photoThumbnail);

                    session.UndoAll();
                }
            }
            ProgressIndicator.IsRunning = false;
        }
        private void speak_Click(object sender, RoutedEventArgs e)
        {
            string lang = "";


            if (tb.Text == "")
            {
                if (RE.IsChecked == true)
                {
                    tb.Text = "Enter Something Here";
                }
                else if (RF.IsChecked == true)
                {
                    tb.Text = "Entrez quelque chose ici";
                }
                else if (RS.IsChecked == true)
                {
                    tb.Text = "Escriba algo aquí";
                }
                else if (RG.IsChecked == true)
                {
                    tb.Text = "Geben Sie hier etwas";
                }
            }
            else
            {
                if (RE.IsChecked == true)
                {
                    lang = "en";
                }
                else if (RF.IsChecked == true)
                {
                    lang = "fr";
                }
                else if (RS.IsChecked == true)
                {
                    lang = "es";
                }
                else if (RG.IsChecked == true)
                {
                    lang = "de";
                }


                if (Male.IsChecked == true)
                {
                    IEnumerable <VoiceInformation>
                    voices = from voice in InstalledVoices.All
                             where
                             voice.Language.Substring(0, 2).Equals(lang)
                             &&
                             voice.Gender.Equals(VoiceGender.Male)
                             select voice;

                    try
                    {
                        spk.SetVoice(voices.ElementAt(0));
                    }catch (System.InvalidOperationException) {}
                    catch (System.ArgumentOutOfRangeException) {};
                }
                else if (Female.IsChecked == true)
                {
                    IEnumerable <VoiceInformation>
                    voices = from voice in InstalledVoices.All
                             where
                             voice.Language.Substring(0, 2).Equals(lang)
                             &&
                             voice.Gender.Equals(VoiceGender.Female)
                             select voice;
                    try
                    {
                        spk.SetVoice(voices.ElementAt(0));
                    }
                    catch (System.InvalidOperationException)
                    {}
                    catch (System.ArgumentOutOfRangeException) { };
                }


                task = spk.SpeakTextAsync(tb.Text);
                task.AsTask();
            }
        }
예제 #4
0
        public static void RunSynchronously(Windows.Foundation.IAsyncAction iasync)
        {
            var task = iasync.AsTask();

            task.Wait();
        }
        private void speak_Click(object sender, RoutedEventArgs e)
        {
            string lang="";

            if (tb.Text == "")
            {
               if (RE.IsChecked == true)
                {
                    tb.Text = "Enter Something Here";
                }
                else if (RF.IsChecked == true)
                {
                    tb.Text = "Entrez quelque chose ici";

                }
                else if (RS.IsChecked == true)
                {
                    tb.Text = "Escriba algo aquí";
                }
                else if (RG.IsChecked == true)
                {
                    tb.Text = "Geben Sie hier etwas";
                }
            }
            else
            {
                if (RE.IsChecked == true)
                {
                    lang = "en";
                }
                else if (RF.IsChecked == true)
                {
                    lang = "fr";

                }
                else if (RS.IsChecked == true)
                {
                    lang = "es";
                }
                else if (RG.IsChecked == true)
                {
                    lang = "de";
                }

                if (Male.IsChecked == true)
                {
                    IEnumerable<VoiceInformation>
                      voices = from voice in InstalledVoices.All
                               where
                               voice.Language.Substring(0,2).Equals(lang)
                               &&
                               voice.Gender.Equals(VoiceGender.Male)
                               select voice;

                 try
                 {
                     spk.SetVoice(voices.ElementAt(0));

                     }catch(System.InvalidOperationException){}
                    catch(System.ArgumentOutOfRangeException){};

                }
                else if(Female.IsChecked == true)
                {
                    IEnumerable<VoiceInformation>
                      voices = from voice in InstalledVoices.All
                               where
                               voice.Language.Substring(0,2).Equals(lang)
                               &&
                               voice.Gender.Equals(VoiceGender.Female)
                               select voice;
                    try
                    {
                        spk.SetVoice(voices.ElementAt(0));

                    }
                    catch (System.InvalidOperationException)
                    {}
                    catch (System.ArgumentOutOfRangeException) { };
                }

            task=spk.SpeakTextAsync(tb.Text);
            task.AsTask();

            }
        }