Пример #1
0
        private async void ReOpenImageMenuFlyoutItem_Click(object sender, RoutedEventArgs e)
        {
            ContentFrame_Reset();

            WriteableOutputImage = WriteableOutputImageCopy.Clone();
            PrevOutputs.Clear();
            PrevOutputs.Push(WriteableOutputImage.Clone());

            await UpdateOutputImage();
        }
Пример #2
0
        private async void OpenImageMenuFlyoutItem_Click(object sender, RoutedEventArgs e)
        {
            var picker = new FileOpenPicker
            {
                ViewMode = PickerViewMode.Thumbnail,
                SuggestedStartLocation = PickerLocationId.PicturesLibrary
            };

            picker.FileTypeFilter.Add(".bmp");
            picker.FileTypeFilter.Add(".heic");
            picker.FileTypeFilter.Add(".heif");
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");
            picker.FileTypeFilter.Add(".gif");
            picker.FileTypeFilter.Add(".tif");
            picker.FileTypeFilter.Add(".tiff");
            picker.FileTypeFilter.Add(".ppm");
            picker.FileTypeFilter.Add("*");

            StorageFile inputFile = await picker.PickSingleFileAsync();

            if (inputFile != null)
            {
                if (!(IsKnownFile(inputFile.FileType) || IsKnownFileMime(inputFile.ContentType)))
                {
                    if (!(await ShowFileTryOpenDialog()))
                    {
                        return;
                    }
                }
                ContentFrame_Reset();

                ImageFileTextBox.Text = inputFile.Path;

                if (InputImageStream != null)
                {
                    InputImageStream.Dispose();
                    InputImageStream = null;
                }

                if (inputFile.FileType == ".ppm")
                {
                    try
                    {
                        PPMImage ppmImage = await PPMImage.Open(inputFile);

                        WriteableOutputImage = ppmImage.ConvertToWriteableBitmap();
                    }
                    catch (Exception ex)
                    {
                        await ShowErrorDialog("An error occured during file open. Damaged file!\nError message: " + ex.Message);

                        return;
                    }



                    SoftwareBitmap softWriteableOutputImage = SoftwareBitmap.CreateCopyFromBuffer(WriteableOutputImage.PixelBuffer, BitmapPixelFormat.Bgra8, WriteableOutputImage.PixelWidth, WriteableOutputImage.PixelHeight);
                    InputImageStream = await GetRandomAccessStreamFromSoftwareBitmap(softWriteableOutputImage, BitmapEncoder.PngEncoderId);
                    await LoadInputVirtualBitmap();

                    await UpdateOutputImage();
                }
                else
                {
                    try
                    {
                        using (IRandomAccessStream stream = await inputFile.OpenAsync(FileAccessMode.Read))
                        {
                            WriteableBitmap writeableInputImage;

                            BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);

                            SoftwareBitmap softwareBitmap1 = await decoder.GetSoftwareBitmapAsync();

                            ImageResolution.Text = softwareBitmap1.PixelWidth + " x " + softwareBitmap1.PixelHeight;

                            writeableInputImage = new WriteableBitmap(softwareBitmap1.PixelWidth, softwareBitmap1.PixelHeight);
                            writeableInputImage.SetSource(stream);

                            InputImageStream = stream;

                            await LoadInputVirtualBitmap();
                        }

                        //  inputImage.Source = writeableInputImage;


                        using (IRandomAccessStream stream = await inputFile.OpenAsync(FileAccessMode.Read))
                        {
                            BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);

                            SoftwareBitmap softwareBitmap1 = await decoder.GetSoftwareBitmapAsync();

                            WriteableOutputImage = new WriteableBitmap(softwareBitmap1.PixelWidth, softwareBitmap1.PixelHeight);
                            WriteableOutputImage.SetSource(stream);
                            WriteableOutputImageCopy = WriteableOutputImage.Clone();

                            PrevOutputs.Push(WriteableOutputImage.Clone());
                            UndoFlyoutItem.IsEnabled = false;

                            await UpdateOutputImage();
                        }
                    }
                    catch (Exception)
                    {
                        await ShowErrorDialog("An error occured during file open. Damaged file!");

                        return;
                    }
                }

                //outputImage.Source = writableOutputImage;
            }
            else
            {
                //Operation cancelled
                return;
            }

            ReopenFlyoutItem.IsEnabled         = true;
            SaveMenuFlyoutItem.IsEnabled       = true;
            EditMenuBarItem.IsEnabled          = true;
            AdvancedToolsMenuBarItem.IsEnabled = true;
            ToolsMenuBarItem.IsEnabled         = true;
            ZoomCommandBar.IsEnabled           = true;

            //await Open();
        }