Skip to content

Commit

Permalink
WinForms: Add PNG/JFIF clipboard formats when copying
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanfish committed Jan 10, 2024
1 parent 26cbaab commit e301b89
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions NAPS2.Lib.WinForms/EtoForms/WinForms/WinFormsEtoPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e301b89

Please sign in to comment.