private void OpenFileFromDrag(string path)
 {
     SetMode(Modes.SingleImage);
     _currentImage     = PalasoImage.FromFile(path);
     _pictureBox.Image = _currentImage.Image;
     ImageToolboxSettings.Default.LastImageFolder = Path.GetDirectoryName(path);
     ImageToolboxSettings.Default.Save();
     if (ImageChanged != null)
     {
         ImageChanged.Invoke(this, null);
     }
 }
        private void OnGetFromFileSystemClick(object sender, EventArgs e)
        {
            SetMode(Modes.SingleImage);
#if MONO
            using (var dlg = new OpenFileDialog())
#else
            // The primary thing that OpenFileDialogWithViews buys us is the ability to default to large icons.
            // OpenFileDialogWithViews still doesn't let us read (and thus remember) the selected view.
            using (var dlg = new OpenFileDialogWithViews(OpenFileDialogWithViews.DialogViewTypes.Large_Icons))
#endif
            {
#if __MonoCS__
                // OpenFileDialogWithViews is Windows-only.  Until we need more of its functionality elsewhere,
                // it's much simpler to implement the one method we need here for Mono/Linux.
                SelectLargeIconView(dlg);
#endif
                if (string.IsNullOrEmpty(ImageToolboxSettings.Default.LastImageFolder))
                {
                    dlg.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
                }
                else
                {
                    dlg.InitialDirectory = ImageToolboxSettings.Default.LastImageFolder;;
                }

                //NB: dissallowed gif because of a .net crash:  http://jira.palaso.org/issues/browse/BL-85
                dlg.Filter = "picture files".Localize("ImageToolbox.PictureFiles", "Shown in the file-picking dialog to describe what kind of files the dialog is filtering for") + "(*.png;*.tif;*.tiff;*.jpg;*.jpeg;*.bmp)|*.png;*.tif;*.tiff;*.jpg;*.jpeg;*.bmp;";

                if (DialogResult.OK == dlg.ShowDialog())
                {
                    ImageToolboxSettings.Default.LastImageFolder = Path.GetDirectoryName(dlg.FileName);
                    ImageToolboxSettings.Default.Save();

                    try
                    {
                        _currentImage = PalasoImage.FromFile(dlg.FileName);
                    }
                    catch (Exception err)                     //for example, http://jira.palaso.org/issues/browse/BL-199
                    {
                        Palaso.Reporting.ErrorReport.NotifyUserOfProblem(err, "Sorry, there was a problem loading that image.".Localize("ImageToolbox.ProblemLoadingImage"));
                        return;
                    }
                    _pictureBox.Image = _currentImage.Image;
                    if (ImageChanged != null)
                    {
                        ImageChanged.Invoke(this, null);
                    }
                }
            }
        }
Exemple #3
0
 public PalasoImage GetImage()
 {
     if (ChosenPath != null && File.Exists(ChosenPath))
     {
         try
         {
             return(PalasoImage.FromFile(ChosenPath));
         }
         catch (Exception error)
         {
             Palaso.Reporting.ErrorReport.ReportNonFatalExceptionWithMessage(error, "There was a problem choosing that image.");
             return(_previousImage);
         }
     }
     return(_previousImage);
 }
        private void GetFromDevice(ImageAcquisitionService.DeviceKind deviceKind)
        {
            //_pictureBox.Image = SampleImages.sampleScan;
            try
            {
                var acquisitionService = new ImageAcquisitionService(deviceKind);

                var wiaImageFile = acquisitionService.Acquire();
                if (wiaImageFile == null)
                {
                    return;
                }

                var imageFile = ConvertToPngOrJpegIfNotAlready(wiaImageFile);
                _currentImage     = PalasoImage.FromFile(imageFile);
                _pictureBox.Image = _currentImage.Image;

                if (ImageChanged != null)
                {
                    ImageChanged.Invoke(this, null);
                }
            }
            catch (ImageDeviceNotFoundException error)
            {
                _messageLabel.Text = error.Message + Environment.NewLine + Environment.NewLine +
                                     "Note: this program works with devices that have a 'WIA' driver, not the old-style 'TWAIN' driver";
                _messageLabel.Visible = true;
            }
            catch (WIA_Version2_MissingException error)
            {
                _messageLabel.Text    = "Windows XP does not come with a crucial DLL that lets you use a WIA scanner with this program. Get a technical person to downloand and follow the directions at http://vbnet.mvps.org/files/updates/wiaautsdk.zip";
                _messageLabel.Visible = true;
            }
            catch (Exception error)
            {
                Palaso.Reporting.ErrorReport.NotifyUserOfProblem(error, "Problem Getting Image".Localize("ImageToolbox.ProblemGettingImageFromDevice"));
            }
        }
        private void OnGetFromFileSystemClick(object sender, EventArgs e)
        {
            SetMode(Modes.SingleImage);
//#if MONO
//			            using (var dlg = new OpenFileDialog())
//            {
//                if (string.IsNullOrEmpty(ImageToolboxSettings.Default.LastImageFolder))
//                {
//                    dlg.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
//                }
//                else
//                {
//                    dlg.InitialDirectory = ImageToolboxSettings.Default.LastImageFolder;
//                }
//
//                dlg.Filter = "picture files|*.png;*.tif;*.tiff;*.jpg;*.jpeg;*.bmp;";
//                dlg.Multiselect = false;
//                dlg.AutoUpgradeEnabled = true;
//				if (DialogResult.OK == dlg.ShowDialog())
//                {
//                    _currentImage = PalasoImage.FromFile(dlg.FileName);
//                    _pictureBox.Image = _currentImage.Image;
//                    ImageToolboxSettings.Default.LastImageFolder = Path.GetDirectoryName(dlg.FileName);
//                    ImageToolboxSettings.Default.Save();
//                    if (ImageChanged != null)
//                        ImageChanged.Invoke(this, null);
//                }
//			}
//#else
#if MONO
            using (var dlg = new OpenFileDialog())
#else
            //The primary thing this OpenFileDialogEx buys us is that with the standard one, there's
            //no way pre-set, what "view" the user gets. With the standard dialog,
            //we had complaints that a user had to change the view to show icons *each time* they used this.
            //Now, OpenFileDialogWithViews still doesn't let us read (and thus remember) the selected view.

            using (var dlg = new OpenFileDialogWithViews(OpenFileDialogWithViews.DialogViewTypes.Large_Icons))
#endif
            {
                if (string.IsNullOrEmpty(ImageToolboxSettings.Default.LastImageFolder))
                {
                    dlg.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
                }
                else
                {
                    dlg.InitialDirectory = ImageToolboxSettings.Default.LastImageFolder;;
                }

                //NB: dissallowed gif because of a .net crash:  http://jira.palaso.org/issues/browse/BL-85
                dlg.Filter = "picture files".Localize("ImageToolbox.PictureFiles", "Shown in the file-picking dialog to describe what kind of files the dialog is filtering for") + "(*.png;*.tif;*.tiff;*.jpg;*.jpeg;*.bmp)|*.png;*.tif;*.tiff;*.jpg;*.jpeg;*.bmp;";

                if (DialogResult.OK == dlg.ShowDialog())
                {
                    ImageToolboxSettings.Default.LastImageFolder = Path.GetDirectoryName(dlg.FileName);
                    ImageToolboxSettings.Default.Save();

                    try
                    {
                        _currentImage = PalasoImage.FromFile(dlg.FileName);
                    }
                    catch (Exception err)                     //for example, http://jira.palaso.org/issues/browse/BL-199
                    {
                        Palaso.Reporting.ErrorReport.NotifyUserOfProblem(err, "Sorry, there was a problem loading that image.".Localize("ImageToolbox.ProblemLoadingImage"));
                        return;
                    }
                    _pictureBox.Image = _currentImage.Image;
                    if (ImageChanged != null)
                    {
                        ImageChanged.Invoke(this, null);
                    }
                }
            }
        }