b-init / ImagePaste

A simple Blender addon to grab images from your clipboard and paste as a reference image in viewport or onto the image editor.
GNU General Public License v3.0
246 stars 9 forks source link

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

Closed teetow closed 2 years ago

thanhph111 commented 2 years ago

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

thanhph111 commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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