コード例 #1
0
        private async Task InitializeAsync(FileSystemStorageFile PdfFile)
        {
            LoadingControl.IsLoading = true;

            try
            {
                using (IRandomAccessStream PdfStream = await PdfFile.GetRandomAccessStreamFromFileAsync(FileAccessMode.Read))
                {
                    try
                    {
                        Pdf = await PdfDocument.LoadFromStreamAsync(PdfStream);
                    }
                    catch (Exception)
                    {
                        PdfPasswordDialog Dialog = new PdfPasswordDialog();

                        if ((await Dialog.ShowAsync()) == ContentDialogResult.Primary)
                        {
                            Pdf = await PdfDocument.LoadFromStreamAsync(PdfStream, Dialog.Password);
                        }
                        else
                        {
                            Frame.GoBack();
                            return;
                        }
                    }
                }

                NumIndicator.Text   = Convert.ToString(Pdf.PageCount);
                TextBoxControl.Text = "1";

                for (uint i = 0; i < Pdf.PageCount; i++)
                {
                    PdfCollection.Add(new BitmapImage());
                    LoadTable.Add(i);
                }

                Flip.ItemsSource = PdfCollection;

                await JumpToPageIndexAsync(0);
            }
            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();

                Frame.GoBack();
            }
            finally
            {
                await Task.Delay(500);

                LoadingControl.IsLoading = false;
            }
        }
コード例 #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 = await GetArtistAsync().ConfigureAwait(true);

                    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;
                }
                }
            }
        }
コード例 #3
0
        private async void Save_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            LoadingControl.IsLoading = 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;

            Frame.GoBack();
        }
コード例 #4
0
        private async void TranscodeImage_Click(object sender, RoutedEventArgs e)
        {
            FileSystemStorageFile Item = PhotoCollection[Flip.SelectedIndex].PhotoFile;

            TranscodeImageDialog Dialog = null;

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

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

            if (await Dialog.ShowAsync() == ContentDialogResult.Primary)
            {
                TranscodeLoadingControl.IsLoading = true;

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

                await Task.Delay(500);

                TranscodeLoadingControl.IsLoading = false;
            }
        }
コード例 #5
0
        private async Task InitializeAsync()
        {
            try
            {
                using (IRandomAccessStream Stream = await MediaFile.GetRandomAccessStreamFromFileAsync(FileAccessMode.Read))
                {
                    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 = await GetArtistAsync();

                        Item.ApplyDisplayProperties(Props);

                        if (await GetMusicCoverAsync() 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;
                    }
                    }
                }
            }
            catch (Exception ex)
            {
                LogTracer.Log(ex, "Could not load media because an exception was threw");

                QueueContentDialog Dialog = new QueueContentDialog
                {
                    Title           = Globalization.GetString("Common_Dialog_ErrorTitle"),
                    Content         = Globalization.GetString("QueueDialog_CouldNotLoadMedia_Content"),
                    CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton")
                };

                await Dialog.ShowAsync();

                Frame.GoBack();
            }
        }
コード例 #6
0
        private async Task Initialize(FileSystemStorageFile PdfFile)
        {
            LoadingControl.IsLoading = true;

            PdfCollection.Clear();
            LoadQueue.Clear();

            Cancellation  = new CancellationTokenSource();
            MaxLoad       = 0;
            LastPageIndex = 0;

            try
            {
                using (IRandomAccessStream PdfStream = await PdfFile.GetRandomAccessStreamFromFileAsync(FileAccessMode.Read))
                {
                    try
                    {
                        Pdf = await PdfDocument.LoadFromStreamAsync(PdfStream);
                    }
                    catch (Exception)
                    {
                        PdfPasswordDialog Dialog = new PdfPasswordDialog();

                        if ((await Dialog.ShowAsync()) == 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, new PdfPageRenderOptions
                            {
                                DestinationHeight = Convert.ToUInt32(Page.Size.Height * 1.5),
                                DestinationWidth  = Convert.ToUInt32(Page.Size.Width * 1.5)
                            });

                            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();

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

                await Task.Delay(1000);

                LoadingControl.IsLoading = false;
            }
        }
コード例 #7
0
        private async Task Initialize(FileSystemStorageFile PdfFile)
        {
            LoadingControl.IsLoading = 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;
            }
        }