Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clipboard_get_image doesn't work for Bitmaps on Windows #83201

Closed
gokiburikin opened this issue Oct 12, 2023 · 4 comments · Fixed by #88405
Closed

clipboard_get_image doesn't work for Bitmaps on Windows #83201

gokiburikin opened this issue Oct 12, 2023 · 4 comments · Fixed by #88405

Comments

@gokiburikin
Copy link

gokiburikin commented Oct 12, 2023

Godot version

v4.2.dev2.official [da81ca6]

System information

Godot v4.2.dev2 - Windows 10.0.19044 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 970 (NVIDIA; 31.0.15.3623) - Intel(R) Core(TM) i7-10700K CPU @ 3.80GHz (16 Threads)

Issue description

clipboard_get_image works in some contexts (PNG data) but fails with an empty image error or hard crash in others (Bitmap/DIB/V5 data.) I tested with this image: https://godotengine.org/assets/press/logo_large_color_light.png

For non-browser applications I pasted from Chrome (which works) and then copied again before pasting (which fails.) For ShareX I took a screen capture of the image.

Working:

Google Chrome (Copy Image)
Microsoft Edge (Copy Image)
ShareX (Copy image to clipboard, UseAlternativeClipboardCopyImage True)

Empty Image (Failure):

Firefox (Copy Image)
ShareX (Copy image to clipboard, UseAlternativeClipboardCopyImage False)

Crash (Failure):

MSPaint (Ctrl + C)
ClipStudioPaint 2.1.4 (Ctrl + C)
Krita 3.1.4 (Ctrl + C)

The clipboards that work have PNG data in them (according to Free Clipboard Viewer) and the others have either a lot of extraneous information (Firefox) or Bitmap/DIB/V5.

I went back to 4.2dev2 (which I think is the earliest dev release after #63826 was merged) to test this, but it still doesn't work in 4.2dev5.

Steps to reproduce

Copy this image from different applications and attempt to create an Image from it using clipboard_get_image.

Minimal reproduction project

clipboard-image-mrp.zip

@gokiburikin
Copy link
Author

Just a bit more info: ShareX clipboard behaviour can be changed in the advanced application settings which allows clipboard_get_image to work with ShareX.

image

@lostminds
Copy link

Perhaps Clipboard.ContainsImage() and Clipboard.GetImage() could be used instead to access Bitmap image data on the clipboard? Looks like a little extra work would be needed to get the bmp data from the returned BitmapSource, but maybe it's more reliable than GetClipboardData(CF_DIB) in getting the various flavors of bitmap data that can be placed on the windows clipboard? At least it looks like it's intended to be.

@akien-mga akien-mga modified the milestones: 4.2, 4.3 Nov 14, 2023
@KoBeWi
Copy link
Member

KoBeWi commented Feb 12, 2024

I ran into a similar issue. Depending on the source program, clipboard_get_image() crashes in official builds, and in dev build it returns corrupted data:
image
I tested with GIMP (works) and IrfanView (corrupted).

4.3 dev3

@bruvzg
Copy link
Member

bruvzg commented Feb 16, 2024

If it's DIB image, it might be already fixed by #88220, I'll take a look (it mihgt need some extra decoding for some DIB formats).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants