diff --git a/NAPS2.Lib.Gtk/EtoForms/Gtk/GtkEtoPlatform.cs b/NAPS2.Lib.Gtk/EtoForms/Gtk/GtkEtoPlatform.cs index f348225bcc..259502af77 100644 --- a/NAPS2.Lib.Gtk/EtoForms/Gtk/GtkEtoPlatform.cs +++ b/NAPS2.Lib.Gtk/EtoForms/Gtk/GtkEtoPlatform.cs @@ -44,6 +44,11 @@ public override Bitmap ToBitmap(IMemoryImage image) return new Bitmap(new BitmapHandler(pixbuf)); } + public override IMemoryImage FromBitmap(ImageContext imageContext, Bitmap bitmap) + { + return new GtkImage(imageContext, bitmap.ToGdk()); + } + public override void SetClipboardImage(Clipboard clipboard, Bitmap image) { // Without cloning the image, Gtk gives errors on paste. diff --git a/NAPS2.Lib.Mac/EtoForms/Mac/MacEtoPlatform.cs b/NAPS2.Lib.Mac/EtoForms/Mac/MacEtoPlatform.cs index 29393f8952..0f0fcb78ca 100644 --- a/NAPS2.Lib.Mac/EtoForms/Mac/MacEtoPlatform.cs +++ b/NAPS2.Lib.Mac/EtoForms/Mac/MacEtoPlatform.cs @@ -61,6 +61,11 @@ public override Bitmap ToBitmap(IMemoryImage image) return new Bitmap(new BitmapHandler((NSImage) nsImage.Copy())); } + public override IMemoryImage FromBitmap(ImageContext imageContext, Bitmap bitmap) + { + return new MacImage(imageContext, bitmap.ToNS()); + } + public override IMemoryImage DrawHourglass(ImageContext imageContext, IMemoryImage image) { // TODO diff --git a/NAPS2.Lib.WinForms/EtoForms/WinForms/WinFormsEtoPlatform.cs b/NAPS2.Lib.WinForms/EtoForms/WinForms/WinFormsEtoPlatform.cs index 406c2c89c3..482ab19bc5 100644 --- a/NAPS2.Lib.WinForms/EtoForms/WinForms/WinFormsEtoPlatform.cs +++ b/NAPS2.Lib.WinForms/EtoForms/WinForms/WinFormsEtoPlatform.cs @@ -120,6 +120,11 @@ public override Bitmap ToBitmap(IMemoryImage image) return bitmap.ToEto(); } + public override IMemoryImage FromBitmap(ImageContext imageContext, Bitmap bitmap) + { + return new GdiImage(imageContext, (SD.Bitmap) bitmap.ToSD()); + } + public override IMemoryImage DrawHourglass(ImageContext imageContext, IMemoryImage image) { var bitmap = new System.Drawing.Bitmap(image.Width, image.Height); diff --git a/NAPS2.Lib/EtoForms/Desktop/DesktopController.cs b/NAPS2.Lib/EtoForms/Desktop/DesktopController.cs index 8ee78902eb..08d9caf6b8 100644 --- a/NAPS2.Lib/EtoForms/Desktop/DesktopController.cs +++ b/NAPS2.Lib/EtoForms/Desktop/DesktopController.cs @@ -1,4 +1,5 @@ using System.Threading; +using Eto.Drawing; using Eto.Forms; using NAPS2.EtoForms.Notifications; using NAPS2.ImportExport; @@ -346,6 +347,18 @@ public void Paste() { ImportDirect(_imageTransfer.GetFromClipboard(), true); } + else if (Clipboard.Instance.ContainsImage) + { + var etoBitmap = (Bitmap) Clipboard.Instance.Image; + Task.Run(() => + { + var image = EtoPlatform.Current.FromBitmap(_scanningContext.ImageContext, etoBitmap); + var processedImage = _scanningContext.CreateProcessedImage(image); + processedImage = ImportPostProcessor.AddPostProcessingData(processedImage, image, + _thumbnailController.RenderSize, new BarcodeDetectionOptions(), true); + _desktopImagesController.ReceiveScannedImage()(processedImage); + }); + } } public async Task Copy() diff --git a/NAPS2.Lib/EtoForms/EtoPlatform.cs b/NAPS2.Lib/EtoForms/EtoPlatform.cs index cea697f3f3..be24a1222c 100644 --- a/NAPS2.Lib/EtoForms/EtoPlatform.cs +++ b/NAPS2.Lib/EtoForms/EtoPlatform.cs @@ -23,6 +23,7 @@ public static EtoPlatform Current public abstract IListView CreateListView(ListViewBehavior behavior) where T : notnull; public abstract void ConfigureImageButton(Button button, bool big); public abstract Bitmap ToBitmap(IMemoryImage image); + public abstract IMemoryImage FromBitmap(ImageContext imageContext, Bitmap bitmap); public abstract IMemoryImage DrawHourglass(ImageContext imageContext, IMemoryImage thumb); public abstract void SetFrame(Control container, Control control, Point location, Size size, bool inOverlay); public abstract Control CreateContainer(); diff --git a/NAPS2.Lib/EtoForms/Ui/DesktopForm.cs b/NAPS2.Lib/EtoForms/Ui/DesktopForm.cs index b53cbf1310..d97cd3def3 100644 --- a/NAPS2.Lib/EtoForms/Ui/DesktopForm.cs +++ b/NAPS2.Lib/EtoForms/Ui/DesktopForm.cs @@ -145,7 +145,7 @@ private void OpeningContextMenu(object? sender, EventArgs e) if (!EtoPlatform.Current.IsMac) { // TODO: Can't do this on Mac yet as it disables the menu item indefinitely - Commands.Paste.Enabled = _imageTransfer.IsInClipboard(); + Commands.Paste.Enabled = _imageTransfer.IsInClipboard() || Clipboard.Instance.ContainsImage; } if (ImageList.Selection.Any()) {