private async void TranscodeImage_Click(object sender, RoutedEventArgs e)
        {
            FileSystemStorageItemBase Item = PhotoCollection[Flip.SelectedIndex].PhotoFile;

            TranscodeImageDialog Dialog = null;

            using (IRandomAccessStream OriginStream = await Item.GetRandomAccessStreamFromFileAsync(FileAccessMode.Read).ConfigureAwait(true))
            {
                BitmapDecoder Decoder = await BitmapDecoder.CreateAsync(OriginStream);

                Dialog = new TranscodeImageDialog(Decoder.PixelWidth, Decoder.PixelHeight);
            }

            if (await Dialog.ShowAsync().ConfigureAwait(true) == ContentDialogResult.Primary)
            {
                TranscodeLoadingControl.IsLoading  = true;
                MainPage.ThisPage.IsAnyTaskRunning = true;

                await GeneralTransformer.TranscodeFromImageAsync(Item, Dialog.TargetFile, Dialog.IsEnableScale, Dialog.ScaleWidth, Dialog.ScaleHeight, Dialog.InterpolationMode).ConfigureAwait(true);

                await Task.Delay(1000).ConfigureAwait(true);

                TranscodeLoadingControl.IsLoading  = false;
                MainPage.ThisPage.IsAnyTaskRunning = false;
            }
        }
Example #2
0
        private async Task Initialize()
        {
            using (IRandomAccessStream Stream = await MediaFile.GetRandomAccessStreamFromFileAsync(FileAccessMode.Read).ConfigureAwait(true))
            {
                Source = MediaSource.CreateFromStream(Stream, MIMEDictionary[MediaFile.Type.ToLower()]);
                MediaPlaybackItem Item = new MediaPlaybackItem(Source);

                switch (MediaFile.Type.ToLower())
                {
                case ".mp3":
                case ".flac":
                case ".wma":
                case ".m4a":
                {
                    MusicCover.Visibility = Visibility.Visible;

                    MediaItemDisplayProperties Props = Item.GetDisplayProperties();
                    Props.Type = Windows.Media.MediaPlaybackType.Music;
                    Props.MusicProperties.Title       = MediaFile.DisplayName;
                    Props.MusicProperties.AlbumArtist = GetArtist();

                    Item.ApplyDisplayProperties(Props);

                    if (await GetMusicCoverAsync().ConfigureAwait(true) is BitmapImage Thumbnail)
                    {
                        Cover.Source     = Thumbnail;
                        Cover.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        Cover.Visibility = Visibility.Collapsed;
                    }

                    Display.Text     = $"{Globalization.GetString("Media_Tip_Text")} {MediaFile.DisplayName}";
                    MVControl.Source = Item;
                    break;
                }

                default:
                {
                    MusicCover.Visibility = Visibility.Collapsed;

                    MediaItemDisplayProperties Props = Item.GetDisplayProperties();
                    Props.Type = Windows.Media.MediaPlaybackType.Video;
                    Props.VideoProperties.Title = MediaFile.DisplayName;
                    Item.ApplyDisplayProperties(Props);

                    MVControl.Source = Item;
                    break;
                }
                }
            }
        }
        private async void Save_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            LoadingControl.IsLoading           = true;
            MainPage.ThisPage.IsAnyTaskRunning = true;

            using (IRandomAccessStream Stream = await OriginFile.GetRandomAccessStreamFromFileAsync(FileAccessMode.ReadWrite).ConfigureAwait(true))
            {
                switch (OriginFile.Type.ToLower())
                {
                case ".png":
                    await Cropper.SaveAsync(Stream, BitmapFileFormat.Png).ConfigureAwait(true);

                    break;

                case ".jpg":
                case ".jpeg":
                    await Cropper.SaveAsync(Stream, BitmapFileFormat.Jpeg).ConfigureAwait(true);

                    break;

                case ".bmp":
                    await Cropper.SaveAsync(Stream, BitmapFileFormat.Bmp).ConfigureAwait(true);

                    break;

                case ".gif":
                    await Cropper.SaveAsync(Stream, BitmapFileFormat.Gif).ConfigureAwait(true);

                    break;

                case ".tiff":
                    await Cropper.SaveAsync(Stream, BitmapFileFormat.Tiff).ConfigureAwait(true);

                    break;

                default:
                    await Cropper.SaveAsync(Stream, BitmapFileFormat.Png).ConfigureAwait(true);

                    break;
                }
            }

            await Task.Delay(1000).ConfigureAwait(true);

            LoadingControl.IsLoading           = false;
            MainPage.ThisPage.IsAnyTaskRunning = false;

            Frame.GoBack();
        }
Example #4
0
        private async Task Initialize(FileSystemStorageItemBase PdfFile)
        {
            LoadingControl.IsLoading           = true;
            MainPage.ThisPage.IsAnyTaskRunning = true;

            PdfCollection    = new ObservableCollection <BitmapImage>();
            LoadQueue        = new Queue <int>();
            ExitLocker       = new ManualResetEvent(false);
            Cancellation     = new CancellationTokenSource();
            Flip.ItemsSource = PdfCollection;
            MaxLoad          = 0;
            LastPageIndex    = 0;

            try
            {
                using (IRandomAccessStream PdfStream = await PdfFile.GetRandomAccessStreamFromFileAsync(FileAccessMode.Read).ConfigureAwait(true))
                {
                    try
                    {
                        Pdf = await PdfDocument.LoadFromStreamAsync(PdfStream);
                    }
                    catch (Exception)
                    {
                        PdfPasswordDialog Dialog = new PdfPasswordDialog();
                        if ((await Dialog.ShowAsync().ConfigureAwait(true)) == ContentDialogResult.Primary)
                        {
                            Pdf = await PdfDocument.LoadFromStreamAsync(PdfStream, Dialog.Password);
                        }
                        else
                        {
                            Frame.GoBack();
                            return;
                        }
                    }
                }

                for (uint i = 0; i < 10 && i < Pdf.PageCount && !Cancellation.IsCancellationRequested; i++)
                {
                    using (PdfPage Page = Pdf.GetPage(i))
                        using (InMemoryRandomAccessStream PageStream = new InMemoryRandomAccessStream())
                        {
                            await Page.RenderToStreamAsync(PageStream);

                            BitmapImage DisplayImage = new BitmapImage();
                            PdfCollection.Add(DisplayImage);
                            await DisplayImage.SetSourceAsync(PageStream);
                        }
                }
            }
            catch (Exception)
            {
                QueueContentDialog Dialog = new QueueContentDialog
                {
                    Title           = Globalization.GetString("Common_Dialog_ErrorTitle"),
                    Content         = Globalization.GetString("QueueDialog_PDFOpenFailure"),
                    CloseButtonText = Globalization.GetString("Common_Dialog_GoBack")
                };
                _ = await Dialog.ShowAsync().ConfigureAwait(true);

                Frame.GoBack();
            }
            finally
            {
                ExitLocker.Set();

                if (!Cancellation.IsCancellationRequested)
                {
                    Flip.SelectionChanged += Flip_SelectionChanged;
                    Flip.SelectionChanged += Flip_SelectionChanged1;
                }

                await Task.Delay(1000).ConfigureAwait(true);

                LoadingControl.IsLoading           = false;
                MainPage.ThisPage.IsAnyTaskRunning = false;
            }
        }