From e301b89911db2e706869f6c38395ce0630724982 Mon Sep 17 00:00:00 2001 From: Ben Olden-Cooligan Date: Tue, 9 Jan 2024 21:03:45 -0800 Subject: [PATCH] WinForms: Add PNG/JFIF clipboard formats when copying #264 --- .../EtoForms/WinForms/WinFormsEtoPlatform.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/NAPS2.Lib.WinForms/EtoForms/WinForms/WinFormsEtoPlatform.cs b/NAPS2.Lib.WinForms/EtoForms/WinForms/WinFormsEtoPlatform.cs index e7a4cad374..a8c721bd42 100644 --- a/NAPS2.Lib.WinForms/EtoForms/WinForms/WinFormsEtoPlatform.cs +++ b/NAPS2.Lib.WinForms/EtoForms/WinForms/WinFormsEtoPlatform.cs @@ -242,6 +242,15 @@ public override void ConfigureZoomButton(Button button) public override void SetClipboardImage(Clipboard clipboard, ProcessedImage processedImage, IMemoryImage memoryImage) { + // We also add the JPEG/PNG format to the clipboard as some applications care about the actual format + // https://github.com/cyanfish/naps2/issues/264 + var jpegOrPng = ImageExportHelper.SaveSmallestFormatToMemoryStream(memoryImage, + processedImage.Metadata.Lossless, -1, out var fileFormat); + var handler = (ClipboardHandler) clipboard.Handler; + // Note this only updates the DataObject, it doesn't set the clipboard, that's done in the + // base.SetClipboardImage(...) call below + handler.Control.SetData(fileFormat == ImageFileFormat.Jpeg ? "JFIF" : "PNG", jpegOrPng); + if (memoryImage.PixelFormat is ImagePixelFormat.BW1 or ImagePixelFormat.Gray8) { // Storing 1bit/8bit images to the clipboard doesn't work, so we copy to 24bit if needed