Closed neighthan closed 5 years ago
So, the images in question are copy-pasted and have a transparent background. I'm using a workaround now where I explicitly set the background to be white; then things work fine with pasting the image using this extension. So, I guess the problem is how transparent backgrounds are handled? I think using white instead of black for the background color when there is none would make more sense. If this is easy to change, it would be a nice fix. Otherwise, I'm content with my explicitly white instead of transparent background workaround for now.
Hello, What operating system do you use?
Windows 10. I don't know that it matters, but I copy the images out of a Jupyter notebook. The notebook server is running on an Ubuntu machine, but I access the client from Windows.
@kivle Hello friend, do you know why?
In file res/pc.ps1
:
$img = [Windows.Clipboard]::GetImage()
$fcb = new-object Windows.Media.Imaging.FormatConvertedBitmap($img, [Windows.Media.PixelFormats]::Rgb24, $null, 0)
It get bitmap from clipboard with Rgb24
mode. Rgb24
it seems without aplha value, so get a black backgroud?
@neighthan Could you run res/pc.ps1
(powershell script) in your Win10, and test with Rgb24
and Rgba64
?
Yes, using Rgba64
instead of Rgb24
fixes this issue!
Okay, the issue seems a bit more complicated. If I copy + paste an image from a Jupyter notebook, it has the black background unless I use Rgba64
, then it works. But if I paste in an image that I copied from a screenshot tool, using Rgb24
works and Rgba64
gives an empty image. I assume that the screenshot tool is only copying an RGB image to the clipboard instead of RGBA. Thus a proper solution to this would need to determine when to use each of these - any idea how to do that?
Or, if that's difficult, one workaround might be to have two separate commands that can be bound - one which uses Rgb24
for pasting and the other for Rgba64
. Keeping Rgb24
as the default would mean nothing is broken for existing users, and anybody who has RGBA images can then just bind the new command to a different shortcut. One command that's smart about the image encoding would be nicer, but I'd be fine with two commands if that leads to a faster solution.
I have no Powershell experience, but I used the lines from your script to get images from the clipboard to test on. For both an image that pastes properly with Rgba64
and for one that doesn't, Powershell has the same $img.Format
(Bgra32
). I tried using Bgra32
instead of Rgba64
, but it also gives a blank image. If Powershell says the format for the two images is the same, I'm not sure what's wrong / how to detect which method to use.
Hello, thank you for you research.
I use Rgba64 test in my windows, and it's ok for normal png or png with transparent background.
I publish a new version(1.0.3). You can try it!
Hi. I have this issue, copying from Jupyter Lab to MS-Word...
Please, could someone be more clear about how to fix it? I'm not familiar (or better saying, completely ignorant!) with PowerShell operations... how to change RGB24 to RGBA64?
thanks
I'm getting some weird results from pasting graphs recently. Here's an example image pasted directly into GitHub:
And here's a screenshot of what that image looks like when I paste it into a markdown document:
Any idea what could be causing this / how to fix it?