コード例 #1
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            var args = e.Parameter as Windows.ApplicationModel.Activation.IActivatedEventArgs;

            if (args?.Kind == Windows.ApplicationModel.Activation.ActivationKind.File)
            {
                var    fileArgs    = args as Windows.ApplicationModel.Activation.FileActivatedEventArgs;
                string strFilePath = fileArgs.Files[0].Path;
                var    file        = (StorageFile)fileArgs.Files[0];
                if (file != null)
                {
                    // Application now has read/write access to the picked file
                    try
                    {
                        OpenFile(file);
                    }
                    catch (System.Exception ex)
                    {
                        ExceptionDisplay.display(ex.Message + ex.StackTrace);
                    }
                }
                else
                {
                    ExceptionDisplay.display("No file selected");
                }
            }
        }
コード例 #2
0
        public static void ReadProgress(string path, double percent)
        {
            using (var fileStream = File.OpenRead(path))
            {
                try
                {
                    using (var progressStream = new ProgressBarStream(fileStream, percent))
                    {
                        progressStream.Progress += Display_Progress;

                        var array = new byte[fileStream.Length];

                        var count = progressStream.Length / 100.0 * percent;

                        progressStream.Read(array, 0, (int)count);

                        var textFromFile = System.Text.Encoding.Default.GetString(array);

                        Console.WriteLine();

                        Console.WriteLine($"Read text: \n  {textFromFile}");
                    }
                }
                catch (Exception e)
                {
                    ExceptionDisplay.Display(e);
                }
            }
        }
コード例 #3
0
        private async void appBarImageChooseClick(object sender, RoutedEventArgs e)
        {
            FileOpenPicker filePicker = new FileOpenPicker()
            {
                ViewMode = PickerViewMode.Thumbnail,
                SuggestedStartLocation = PickerLocationId.ComputerFolder
            };

            filePicker.FileTypeFilter.Add(".nef");
            // filePicker.FileTypeFilter.Add(".tiff");
            // filePicker.FileTypeFilter.Add(".tif");
            filePicker.FileTypeFilter.Add(".dng");
            // filePicker.FileTypeFilter.Add(".cr2");
            filePicker.FileTypeFilter.Add(".jpg");
            //filePicker.FileTypeFilter.Add(".jpeg");
            //filePicker.FileTypeFilter.Add(".png");
            StorageFile file = await filePicker.PickSingleFileAsync();

            if (file != null)
            {
                // Application now has read/write access to the picked file
                try
                {
                    OpenFile(file);
                }
                catch (Exception ex)
                {
                    ExceptionDisplay.display(ex.Message + ex.StackTrace);
                }
            }
            else
            {
                //TODO
            }
        }
コード例 #4
0
        public static void Read(string path, string password)
        {
            using (var fileStream = File.OpenRead(path))
            {
                try
                {
                    using (var protectedStream = new ProtectedStream(fileStream, password))
                    {
                        var array = new byte[fileStream.Length];

                        protectedStream.Read(array, 0, array.Length);

                        string textFromFile = System.Text.Encoding.Default.GetString(array);

                        Console.WriteLine($"Text from file: \n {textFromFile}");
                    }
                }
                catch (Exception e)
                {
                    ExceptionDisplay.Display(e);
                }
            }
        }
コード例 #5
0
        static void Main(string[] args)
        {
            try
            {
                Console.Write($"Euclid Nod = {Euclid.Nod(48, 64, out var ticks)} ");
                Console.WriteLine($"Elapsed time: {ticks} ticks");

                Console.Write($"Binary Nod = {Euclid.BinaryNod(48, 64, out ticks)} ");
                Console.WriteLine($"Elapsed time: {ticks} ticks");

                Console.Write($"Nod of four numbers = {Euclid.Nod(78, 294, 570, 36, out ticks)} ");
                Console.WriteLine($"Elapsed time: {ticks} ticks");

                Console.Write($"Nod with array params = {Euclid.NodWithArrParams(out ticks,  78, 294, 570, 36)} ");
                Console.WriteLine($"Elapsed time: {ticks} ticks");
            }
            catch (Exception e)
            {
                ExceptionDisplay.Display(e);
            }

            Console.ReadKey();
        }
コード例 #6
0
 public MainPage()
 {
     InitializeComponent();
     if (null == metadata)
     {
         try
         {
             StorageFolder installationFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
             var           f = StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/Data/cameras.xml")).AsTask();
             f.Wait();
             var t = f.Result.OpenStreamForReadAsync();
             t.Wait();
             metadata = new CameraMetaData(t.Result);
         }
         catch (CameraMetadataException e)
         {
             ExceptionDisplay.display(e.Message);
         }
     }
     SettingStorage.init();
     NavigationCacheMode = NavigationCacheMode.Enabled;
     imageSelected       = false;
     ApplicationView.GetForCurrentView().SetPreferredMinSize(new Size(200, 100));
 }
コード例 #7
0
        private async void saveButton_Click(object sender, RoutedEventArgs e)
        {
            //TODO reimplement correclty
            //Just for testing purpose for now
            if (raw?.rawData != null)
            {
                var savePicker = new FileSavePicker
                {
                    SuggestedStartLocation = PickerLocationId.DocumentsLibrary,
                    SuggestedFileName      = raw.fileName
                };
                // Dropdown of file types the user can save the file as
                savePicker.FileTypeChoices.Add("Jpeg image file", new List <string>()
                {
                    ".jpg"
                });
                savePicker.FileTypeChoices.Add("PNG image file", new List <string>()
                {
                    ".png"
                });
                //savePicker.FileTypeChoices.Add("PPM image file", new List<string>() { ".ppm" });
                savePicker.FileTypeChoices.Add("TIFF image file", new List <string>()
                {
                    ".tiff"
                });
                savePicker.FileTypeChoices.Add("BitMap image file", new List <string>()
                {
                    ".bmp"
                });
                StorageFile file = await savePicker.PickSaveFileAsync();

                if (file == null)
                {
                    return;
                }

                progressDisplay.Visibility = Visibility.Visible;
                // Prevent updates to the remote version of the file until
                // we finish making changes and call CompleteUpdatesAsync.
                CachedFileManager.DeferUpdates(file);
                var exposure    = exposureSlider.Value;
                int temperature = (int)colorTempSlider.Value;
                var temp        = (int)colorTempSlider.Value;
                var task        = Task.Run(async() =>
                {
                    SoftwareBitmap bitmap = null;
                    //Needs to run in UI thread
                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        bitmap = new SoftwareBitmap(BitmapPixelFormat.Bgra8, raw.dim.x, raw.dim.y);
                    });
                    applyUserModif(ref raw.rawData, raw.dim, raw.mOffset, raw.colorDepth, ref bitmap);
                    // write to file
                    if (file.FileType == ".jpg")
                    {
                        using (var filestream = await file.OpenAsync(FileAccessMode.ReadWrite))
                        {
                            int[] t = new int[3];
                            BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, filestream);
                            var x = encoder.BitmapProperties;

                            //Needs to run in the UI thread because f**k performance
                            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {
                                encoder.SetSoftwareBitmap(bitmap);
                            });
                            await encoder.FlushAsync();
                            encoder = null;
                            bitmap.Dispose();
                        }
                    }
                    else if (file.FileType == ".png")
                    {
                        using (var filestream = await file.OpenAsync(FileAccessMode.ReadWrite))
                        {
                            int[] t = new int[3];
                            BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, filestream);

                            //Needs to run in the UI thread because f**k performance
                            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {
                                //Do some UI-code that must be run on the UI thread.
                                encoder.SetSoftwareBitmap(bitmap);
                            });
                            await encoder.FlushAsync();
                            encoder = null;
                            bitmap.Dispose();
                        }
                    }
                    else if (file.FileType == ".bmp")
                    {
                        using (var filestream = await file.OpenAsync(FileAccessMode.ReadWrite))
                        {
                            int[] t = new int[3];
                            BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.BmpEncoderId, filestream);

                            //Needs to run in the UI thread because f**k performance
                            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {
                                //Do some UI-code that must be run on the UI thread.
                                encoder.SetSoftwareBitmap(bitmap);
                            });
                            await encoder.FlushAsync();
                            encoder = null;
                            bitmap.Dispose();
                        }
                    }

                    /*
                     * else if (file.FileType == ".ppm")
                     * {
                     *  Stream str = await file.OpenStreamForWriteAsync();
                     *  PpmEncoder.WriteToFile(str, ref copyOfimage, raw.dim.y, raw.dim.x, raw.colorDepth);
                     * }*/
                    else
                    {
                        throw new FormatException("Format not supported: " + file.FileType);
                    }
                    // Let Windows know that we're finished changing the file so
                    // the other app can update the remote version of the file.
                    // Completing updates may require Windows to ask for user input.
                    FileUpdateStatus status =
                        await CachedFileManager.CompleteUpdatesAsync(file);

                    if (status != FileUpdateStatus.Complete)
                    {
                        ExceptionDisplay.display("File could not be saved");
                    }
                    await CoreApplication.MainView.CoreWindow.Dispatcher
                    .RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        //Do some UI-code that must be run on the UI thread.
                        //Hide the loading screen
                        progressDisplay.Visibility = Visibility.Collapsed;
                    });
                });
            }
        }
コード例 #8
0
        private void OpenFile(StorageFile file)
        {
            //Add a loading screen
            progressDisplay.Visibility = Visibility.Visible;
            histoLoadingBar.Visibility = Visibility.Visible;
            emptyImage();
            Task t = Task.Run(async() =>
            {
                try
                {
                    Stream stream         = (await file.OpenReadAsync()).AsStreamForRead();
                    RawParser parser      = new RawParser(ref stream);
                    RawDecoder decoder    = parser.decoder;
                    decoder.failOnUnknown = false;
                    decoder.checkSupport(metadata);


                    thumbnail = decoder.decodeThumb();
                    if (thumbnail != null)
                    {
                        //read the thumbnail
                        Task.Run(() =>
                        {
                            if (thumbnail.type == ThumbnailType.JPEG)
                            {
                                displayImage(JpegHelper.getJpegInArrayAsync(thumbnail.data));
                            }
                            else if (thumbnail.type == ThumbnailType.RAW)
                            {
                                //this is a raw image in an array
                                JpegHelper.getThumbnailAsSoftwareBitmap(thumbnail);
                            }
                        });
                    }

                    raw = decoder.decodeRaw();
                    decoder.decodeMetaData(metadata);
                    raw.fileName = file.DisplayName;
                    //read the exifs
                    displayExif();
                    //scale the value
                    //raw.scaleValues();

                    //correctWB
                    //raw.CorrectWB();

                    //demos
                    if (raw.cfa != null && raw.cpp == 1)
                    {
                        Demosaic.demos(ref raw, demosAlgorithm.NearNeighbour);
                    }
                    createPreview();
                    updatePreview();

                    //activate the editing control
                    enableEditingControl(true);
                    //dispose
                    file   = null;
                    parser = null;
                }
                catch (FormatException e)
                {
                    var loader = new Windows.ApplicationModel.Resources.ResourceLoader();
                    var str    = loader.GetString("ExceptionText");
                    ExceptionDisplay.display(str);
                }

                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    //Hide the loading screen
                    progressDisplay.Visibility = Visibility.Collapsed;
                });
            });
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: aleh81/Task--4
        static void Main(string[] args)
        {
            try
            {
                var triangle = new Triangle(4.95, 5.244, 3.11);
                Console.WriteLine(triangle);
            }
            catch (Exception e)
            {
                ExceptionDisplay.Display(e);
            }

            try
            {
                var triangle = new Triangle(6.9, 3.9, 4.1);
                Console.WriteLine(triangle);
            }
            catch (Exception e)
            {
                ExceptionDisplay.Display(e);
            }

            try
            {
                var triangle2 = new Triangle();
                Console.WriteLine(triangle2);
            }
            catch (Exception e)
            {
                ExceptionDisplay.Display(e);
            }

            try
            {
                var triangle3 = new Triangle(9.64, 3.2, 5.972);
                Console.WriteLine(triangle3);
            }
            catch (Exception e)
            {
                ExceptionDisplay.Display(e);
            }

            try
            {
                var triangle4 = new Triangle(0, -2, 10);
                Console.WriteLine(triangle4);
            }
            catch (Exception e)
            {
                ExceptionDisplay.Display(e);
            }

            if (Triangle.Count != 0)
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine($"Count of triangles: {Triangle.Count}");
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Triangles are not defined");
            }

            try
            {
                var triangle1 = new Triangle(5, 5, 5);
                var triangle2 = new Triangle(5, 5, 5);

                Console.WriteLine($"Sum of triangle1 + triangle2 = {triangle1 + triangle2}");
            }
            catch (Exception e)
            {
                ExceptionDisplay.Display(e);
            }

            Console.ReadKey();
        }