public void ShowToolboxWith_PreExisting_EnsureRawFormatUnchanged() { Application.EnableVisualStyles(); PalasoImage i = PalasoImage.FromImage(TestImages.logo); using (var dlg = new ImageToolboxDialog(i, "")) { dlg.ShowDialog(); Assert.AreEqual(ImageFormat.Jpeg.Guid, dlg.ImageInfo.Image.RawFormat.Guid); } }
public void ShowToolbox() { Application.EnableVisualStyles(); using (var dlg = new ImageToolboxDialog(new PalasoImage(),null))// "arrow")) { if (DialogResult.OK == dlg.ShowDialog()) { // File name ending in .tmp will confuse TagLib#...doesn't know what kind of metadata to write. string path = Path.ChangeExtension(Path.GetTempFileName(), ".png"); dlg.ImageInfo.Save(path); Process.Start("explorer.exe", "/select, \"" + path + "\""); } } }
public void ShowToolbox() { Application.EnableVisualStyles(); using (var dlg = new ImageToolboxDialog(new PalasoImage(),null))// "arrow")) { if (DialogResult.OK == dlg.ShowDialog()) { string path = Path.GetTempFileName(); dlg.ImageInfo.Save(path); Process.Start("explorer.exe", "/select, \"" + path + "\""); } } }
public void ShowToolboxWith_PreExisting_Image_WithMetadata() { Application.EnableVisualStyles(); PalasoImage i = PalasoImage.FromImage(LicenseLogos.by_nd); i.Metadata.License = new CreativeCommonsLicense(true,true, CreativeCommonsLicense.DerivativeRules.DerivativesWithShareAndShareAlike); i.Metadata.CopyrightNotice = "Copyright 1992 Papua New Guinea Department of Education and Other Good Things"; i.Metadata.CollectionName = "International Illustrations: The Art Of Reading"; i.Metadata.Creator = "Various Talented Illustrators"; //using (var f = TempFile.WithExtension(".png")) { //i.Save(f.Path); using (var dlg = new ImageToolboxDialog(i, "arrow")) { dlg.ShowDialog(); } } }
private void OnImageToolboxClicked(object sender, EventArgs e) { Application.EnableVisualStyles(); ThumbnailViewer.UseWebViewer = true; using (var dlg = new ImageToolboxDialog(new PalasoImage(), null)) { dlg.ShowDialog(); } }
private void OnSearchGalleryLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { Cursor = Cursors.WaitCursor; var searchString = SearchTermProvider == null ? string.Empty : SearchTermProvider.SearchString; PalasoImage currentImage = null; try { if (!string.IsNullOrEmpty(_relativePathToImage) && File.Exists(GetPathToImage())) { currentImage = PalasoImage.FromFile(GetPathToImage()); } } catch (Exception) { //if we couldn't load it (like if it's missing), best to carry on and let them pick a new one } using (var dlg = new Palaso.UI.WindowsForms.ImageToolbox.ImageToolboxDialog(currentImage ?? new PalasoImage(), searchString)) { if (DialogResult.OK == dlg.ShowDialog(this.ParentForm)) { try { if (File.Exists(GetPathToImage())) { File.Delete(GetPathToImage()); } string fileName = CheckFileName(searchString); if (string.IsNullOrEmpty(fileName)) { fileName = DateTime.UtcNow.ToFileTimeUtc().ToString(); } string fileExt; if ((!String.IsNullOrEmpty(dlg.ImageInfo.FileName)) && (!String.IsNullOrEmpty(dlg.ImageInfo.FileName.Split('.').Last()))) { fileExt = "." + dlg.ImageInfo.FileName.Split('.').Last(); } else { // If no file name or extension, default to png fileExt = ".png"; } fileExt = PalasoImage.FileExtForWebFormat(fileExt); //NB: we have very possible collision if use a real word "bird". //Less so with a time "3409343839", which this only uses if we don't have a file name (e.g. if it came from a scanner) //so this will add to the name if what we have is not unique. if (File.Exists(Path.Combine(_storageFolderPath, fileName + fileExt))) { fileName += "-" + DateTime.UtcNow.ToFileTimeUtc(); } fileName += fileExt; var fullDestPath = Path.Combine(_storageFolderPath, fileName); _relativePathToImage = fullDestPath.Replace(_pathToReferingFile, ""); _relativePathToImage = _relativePathToImage.Trim(Path.DirectorySeparatorChar); dlg.ImageInfo.Save(GetPathToImage()); UpdateDisplay(); NotifyChanged(); } catch (Exception error) { ErrorReport.NotifyUserOfProblem("WeSay was not able to save the picture file.\r\n{0}", error.Message); } } } }
private void OnChangeImage(GeckoDomEventArgs ge) { var imageElement = GetImageNode(ge); if (imageElement == null) return; string currentPath = imageElement.GetAttribute("src").Replace("%20", " "); //TODO: this would let them set it once without us bugging them, but after that if they //go to change it, we would bug them because we don't have a way of knowing that it was a placeholder before. if (!currentPath.ToLower().Contains("placeholder") //always allow them to put in something over a placeholder && !_model.CanChangeImages()) { if(DialogResult.Cancel== MessageBox.Show(LocalizationManager.GetString("EditTab.ImageChangeWarning","This book is locked down as shell. Are you sure you want to change the picture?"),LocalizationManager.GetString("EditTab.ChangeImage","Change Image"),MessageBoxButtons.OKCancel)) { return; } } if (ge.Target.ClassName.Contains("licenseImage")) return; Cursor = Cursors.WaitCursor; var imageInfo = new PalasoImage(); var existingImagePath = Path.Combine(_model.CurrentBook.FolderPath, currentPath); //don't send the placeholder to the imagetoolbox... we get a better user experience if we admit we don't have an image yet. if (!currentPath.ToLower().Contains("placeholder") && File.Exists(existingImagePath)) { try { imageInfo = PalasoImage.FromFile(existingImagePath); } catch (Exception) { //todo: log this } }; Logger.WriteEvent("Showing ImageToolboxDialog Editor Dialog"); using(var dlg = new ImageToolboxDialog(imageInfo, null)) { if(DialogResult.OK== dlg.ShowDialog()) { // var path = MakePngOrJpgTempFileForImage(dlg.ImageInfo.Image); try { _model.ChangePicture(imageElement, dlg.ImageInfo, new NullProgress()); } catch(System.IO.IOException error) { Palaso.Reporting.ErrorReport.NotifyUserOfProblem(error, error.Message); } catch (ApplicationException error) { Palaso.Reporting.ErrorReport.NotifyUserOfProblem(error, error.Message); } catch (Exception error) { Palaso.Reporting.ErrorReport.NotifyUserOfProblem(error,"Bloom had a problem including that image"); } } } Logger.WriteMinorEvent("Emerged from ImageToolboxDialog Editor Dialog"); Cursor = Cursors.Default; }