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

Fallback to System.Drawing.Bitmap if PNG isn't available #33

Merged
merged 1 commit into from
Sep 21, 2022

Conversation

teetow
Copy link
Contributor

@teetow teetow commented Sep 19, 2022

No description provided.

@thanhph111
Copy link
Collaborator

I don't have a Windows to test it for now but do you have any cases where it shows advantages?

@thanhph111 thanhph111 requested review from b-init and removed request for thanhph111 September 19, 2022 14:43
@thanhph111
Copy link
Collaborator

@Yeetus3141 I'm not sure why we didn't come up with this format in the first place. Is there a problem with transparent pixels?

@teetow
Copy link
Contributor Author

teetow commented Sep 19, 2022

Yeah, I just realized the moment I sent this PR off that it won't pick up the alpha channel if there is indeed PNG data on the clipboard. I'm testing a fix locally now where it falls through to System.Drawing.Bitmap only if neither PNG or image/png is present. I'll update the PR.

The reason for this patch is simply that it's a free-for-all on Windows in terms of what formats get put on the clipboard. Some do PNG, some do image/png, some just go ¯\(ツ)/¯ and yeet like 20 formats on there. The System.Drawing.Bitmap seems common enough that I thought it was worth falling back to.

@teetow
Copy link
Contributor Author

teetow commented Sep 19, 2022

PR updated.

It'll try PNG (current behavior), then image/png (used by e.g. XNView) and finally System.Drawing.Bitmap (this is what Windows uses e.g. when you take a screenshot). If none of those formats are present, it'll just give up the way it does currently.

@thanhph111
Copy link
Collaborator

Image format fallback is a good idea, we can have the best of both worlds.

We even started moving to the next version with #32 by using win32 API instead of .NET, but until it solves the alpha channel, I think we will have to live with this clunky sub-process for a while.

@Yeetus3141 will have a look later, thanks a lot.

@b-init
Copy link
Owner

b-init commented Sep 19, 2022

Oh this is great! Especially now that we have fallback. Works fine on Windows. Thanks a lot for improving ImagePaste!

And yes overall this approach is rather slow and we're working to overhaul it. Progress has been slow on my side but I'll update #32

@teetow
Copy link
Contributor Author

teetow commented Sep 19, 2022

Oh this is great! Especially now that we have fallback. Works fine on Windows. Thanks a lot for improving ImagePaste!

Seems only fair, it's such a helpful addon. I use it all the time!

@thanhph111
Copy link
Collaborator

I assume everything works fine, I will release a new patched version real quick. Thank you all, guys 🙏.

@thanhph111 thanhph111 changed the title fix: Handle more formats on Windows Fallback to System.Drawing.Bitmap if PNG isn't available Sep 21, 2022
@thanhph111 thanhph111 merged commit 5380700 into b-init:main Sep 21, 2022
@teetow teetow deleted the win-more-formats branch October 3, 2022 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants