/// <param name="displayPrefix"> /// A descriptive name for the format, such as "OpenRaster". This will be displayed /// in the file dialog's filter. /// </param> /// <param name="extensions">A list of supported file extensions (for example, "jpeg" and "JPEG").</param> /// <param name="importer">The importer for this file format, or null if importing is not supported.</param> /// <param name="exporter">The exporter for this file format, or null if exporting is not supported.</param> public FormatDescriptor(string displayPrefix, string[] extensions, IImageImporter importer, IImageExporter exporter) { if (extensions == null || (importer == null && exporter == null)) { throw new ArgumentNullException("Format descriptor is initialized incorrectly"); } this.Extensions = extensions; this.Importer = importer; this.Exporter = exporter; FileFilter ff = new FileFilter(); StringBuilder formatNames = new StringBuilder(); foreach (string ext in extensions) { if (formatNames.Length > 0) { formatNames.Append(", "); } string wildcard = string.Format("*.{0}", ext); ff.AddPattern(wildcard); formatNames.Append(wildcard); } ff.Name = string.Format(Catalog.GetString("{0} image ({1})"), displayPrefix, formatNames); this.Filter = ff; }
/// <summary> /// Initializes a new instance of the <see cref="ImportedImage"/> class. /// </summary> protected ImportedImage(IImageImporter importer, ImagePrivateData data, PdfDocument document) { Data = data; _document = document; data.Image = this; _importer = importer; }
/// <param name="displayPrefix"> /// A descriptive name for the format, such as "OpenRaster". This will be displayed /// in the file dialog's filter. /// </param> /// <param name="extensions">A list of supported file extensions (for example, "jpeg" and "JPEG").</param> /// <param name="importer">The importer for this file format, or null if importing is not supported.</param> /// <param name="exporter">The exporter for this file format, or null if exporting is not supported.</param> public FormatDescriptor (string displayPrefix, string[] extensions, IImageImporter importer, IImageExporter exporter) { if (extensions == null || (importer == null && exporter == null)) { throw new ArgumentNullException ("Format descriptor is initialized incorrectly"); } this.Extensions = extensions; this.Importer = importer; this.Exporter = exporter; FileFilter ff = new FileFilter (); StringBuilder formatNames = new StringBuilder (); foreach (string ext in extensions) { if (formatNames.Length > 0) formatNames.Append (", "); string wildcard = string.Format ("*.{0}", ext); ff.AddPattern (wildcard); formatNames.Append (wildcard); } ff.Name = string.Format (Catalog.GetString ("{0} image ({1})"), displayPrefix, formatNames); this.Filter = ff; }
// TODO: Standardize add to recent files public bool OpenFile(string file) { bool fileOpened = false; try { // Open the image and add it to the layers IImageImporter importer = PintaCore.System.ImageFormats.GetImporterByFile(file); importer.Import(file); PintaCore.Workspace.ActiveDocument.PathAndFileName = file; PintaCore.Workspace.ActiveWorkspace.History.PushNewItem(new BaseHistoryItem(Stock.Open, Catalog.GetString("Open Image"))); PintaCore.Workspace.ActiveDocument.IsDirty = false; PintaCore.Workspace.ActiveDocument.HasFile = true; PintaCore.Actions.View.ZoomToWindow.Activate(); PintaCore.Workspace.Invalidate(); fileOpened = true; } catch { MessageDialog md = new MessageDialog(PintaCore.Chrome.MainWindow, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, Catalog.GetString("Could not open file: {0}"), file); md.Title = Catalog.GetString("Error"); md.Run(); md.Destroy(); } return(fileOpened); }
// TODO: Standardize add to recent files public bool OpenFile(string file, Window parent = null) { bool fileOpened = false; try { // Open the image and add it to the layers IImageImporter importer = PintaCore.System.ImageFormats.GetImporterByFile(file); importer.Import(file); PintaCore.Workspace.ActiveDocument.PathAndFileName = file; PintaCore.Workspace.ActiveWorkspace.History.PushNewItem(new BaseHistoryItem(Stock.Open, Catalog.GetString("Open Image"))); PintaCore.Workspace.ActiveDocument.IsDirty = false; PintaCore.Workspace.ActiveDocument.HasFile = true; PintaCore.Actions.View.ZoomToWindow.Activate(); PintaCore.Workspace.Invalidate(); fileOpened = true; } catch (UnauthorizedAccessException e) { ShowOpenFileErrorDialog(parent, file, Catalog.GetString("Permission denied"), e.ToString()); } catch (Exception e) { ShowOpenFileErrorDialog(parent, file, e.Message, e.ToString()); } return(fileOpened); }
/// <summary> /// Update the image preview widget of a FileChooserDialog /// </summary> private static void OnUpdateImagePreview(object sender, EventArgs e) { FileChooserDialog dialog = (FileChooserDialog)sender; Image preview = (Image)dialog.PreviewWidget; if (preview.Pixbuf != null) { preview.Pixbuf.Dispose(); } try { Gdk.Pixbuf pixbuf = null; string filename = dialog.PreviewFilename; IImageImporter importer = PintaCore.System.ImageFormats.GetImporterByFile(filename); if (importer != null) { pixbuf = importer.LoadThumbnail(filename, MaxPreviewWidth, MaxPreviewHeight, dialog); } if (pixbuf == null) { dialog.PreviewWidgetActive = false; return; } // Resize the thumbnail in case the importer didn't. if (pixbuf.Width > MaxPreviewWidth || pixbuf.Width > MaxPreviewHeight) { double ratio = Math.Min((double)MaxPreviewWidth / pixbuf.Width, (double)MaxPreviewHeight / pixbuf.Height); var old_pixbuf = pixbuf; pixbuf = pixbuf.ScaleSimple((int)(ratio * pixbuf.Width), (int)(ratio * pixbuf.Height), Gdk.InterpType.Bilinear); old_pixbuf.Dispose(); } // add padding so that small images don't cause the dialog to shrink preview.Xpad = (MaxPreviewWidth - pixbuf.Width) / 2; preview.Pixbuf = pixbuf; dialog.PreviewWidgetActive = true; } catch (GLib.GException) { // if the image preview failed, don't show the preview widget dialog.PreviewWidgetActive = false; } }
// TODO: Standardize add to recent files public bool OpenFile(string file, Window parent = null) { bool fileOpened = false; if (parent == null) { parent = PintaCore.Chrome.MainWindow; } try { // Open the image and add it to the layers IImageImporter importer = PintaCore.System.ImageFormats.GetImporterByFile(file); if (importer == null) { throw new FormatException(Catalog.GetString("Unsupported file format")); } importer.Import(file, parent); PintaCore.Workspace.ActiveDocument.PathAndFileName = file; PintaCore.Workspace.ActiveWorkspace.History.PushNewItem(new BaseHistoryItem(Stock.Open, Catalog.GetString("Open Image"))); PintaCore.Workspace.ActiveDocument.History.SetClean(); PintaCore.Workspace.ActiveDocument.HasFile = true; // This ensures these are called after the window is done being created and sized. // Without it, we sometimes try to zoom when the window has a size of (0, 0). Gtk.Application.Invoke(delegate { PintaCore.Actions.View.ActualSize.Activate(); PintaCore.Workspace.Invalidate(); }); fileOpened = true; } catch (UnauthorizedAccessException e) { ShowOpenFileErrorDialog(parent, file, Catalog.GetString("Permission denied"), e.ToString()); } catch (FormatException e) { ShowUnsupportedFormatDialog(parent, file, e.Message, e.ToString()); } catch (Exception e) { ShowOpenFileErrorDialog(parent, file, e.Message, e.ToString()); } return(fileOpened); }
public void SetUp() { m_OutputDirectory = Path.Combine(Environment.CurrentDirectory, OutputDirectory); if (Directory.Exists(m_OutputDirectory)) { Directory.Delete(m_OutputDirectory, true); } Directory.CreateDirectory(m_OutputDirectory); m_ReferenceFileDescriptions = new List <ImageImporterTestFileDescription> { new ImageImporterTestFileDescription("IMG_5283.CR2", new DateTime(2015, 06, 15), DateTime.Now, FileKind.RawImage), new ImageImporterTestFileDescription("IMG_2584.heic", new DateTime(2015, 06, 15), DateTime.Now, FileKind.Unrecognized), new ImageImporterTestFileDescription("2016-02-27 10.46.01.jpg", new DateTime(2016, 02, 27), DateTime.Now, FileKind.JpegImage), new ImageImporterTestFileDescription("DSC01668.ARW", new DateTime(2019, 09, 26), DateTime.Now, FileKind.RawImage), }; TouchReferenceFiles(); m_ImageImporter = new Importer(); }
/// <summary> /// Update the image preview widget of a FileChooserDialog /// </summary> /// <param name="sender"></param> private static void OnUpdateImagePreview(object sender, EventArgs e) { FileChooserDialog dialog = (FileChooserDialog)sender; Image preview = (Image)dialog.PreviewWidget; if (preview.Pixbuf != null) { preview.Pixbuf.Dispose(); } try { Gdk.Pixbuf pixbuf = null; string filename = dialog.PreviewFilename; IImageImporter importer = PintaCore.System.ImageFormats.GetImporterByFile(filename); if (importer != null) { pixbuf = importer.LoadThumbnail(filename, MaxPreviewWidth, MaxPreviewHeight); } if (pixbuf == null) { dialog.PreviewWidgetActive = false; return; } // add padding so that small images don't cause the dialog to shrink preview.Xpad = (MaxPreviewWidth - pixbuf.Width) / 2; preview.Pixbuf = pixbuf; dialog.PreviewWidgetActive = true; } catch (GLib.GException) { // if the image preview failed, don't show the preview widget dialog.PreviewWidgetActive = false; } }
/// <summary> /// Initializes a new instance of the <see cref="ImportedImageJpeg"/> class. /// </summary> public ImportedImageJpeg(IImageImporter importer, ImagePrivateDataDct data, PdfDocument document) : base(importer, data, document) { }
public ScannedImageImporter(IPdfImporter pdfImporter, IImageImporter imageImporter) { this.pdfImporter = pdfImporter; this.imageImporter = imageImporter; }
/// <summary> /// Initializes a new instance of the <see cref="ImportedImageBitmap"/> class. /// </summary> public ImportedImageBitmap(IImageImporter importer, ImagePrivateDataBitmap data, PdfDocument document) : base(importer, data, document) { }