From 53807003f99b8b66ae48eea9fa799fbf54947b51 Mon Sep 17 00:00:00 2001 From: Johan Althoff Date: Wed, 21 Sep 2022 17:01:04 +0200 Subject: [PATCH] Fallback to `System.Drawing.Bitmap` if `PNG` isn't available (#33) --- imagepaste/clipboard/windows/windows.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/imagepaste/clipboard/windows/windows.py b/imagepaste/clipboard/windows/windows.py index 11736ae..9995d09 100644 --- a/imagepaste/clipboard/windows/windows.py +++ b/imagepaste/clipboard/windows/windows.py @@ -40,6 +40,8 @@ def push(cls, save_directory: str) -> WindowsClipboard: "Add-Type -AssemblyName System.Drawing; " "$clipboard = [System.Windows.Forms.Clipboard]::GetDataObject(); " "$imageStream = $clipboard.GetData('PNG'); " + "if ($null -eq $imageStream) { $imageStream = $clipboard.GetData('image/png') }; " + "if ($null -eq $imageStream) { $imageStream = $clipboard.GetData('System.Drawing.Bitmap') }; " "if ($imageStream) {" "$bitmap = New-Object System.Drawing.Bitmap($imageStream); " f"$bitmap.Save('{filepath}', [System.Drawing.Imaging.ImageFormat]::Png); "