Closed abejfehr closed 1 year ago
Is pngquant compressed data still in PNG format? The clipboard.Write and clipboard.Read both requires the data need to be PNG encoded.
I think so, I added this line:
fmt.Println("header data:", compressedImage[0:8])
and the output was:
header data: [137 80 78 71 13 10 26 10]
which seems to imply it's png data according to this site: http://www.libpng.org/pub/png/spec/1.2/PNG-Structure.html
I think I would've also received this error if that was not the case.
It'd be great if the original bytes could be written to the clipboard without being re-encoded (on Windows)
I am not sure if this is possible. Windows works differently than macOS, and it requires input bytes must be PNG. This package does not do anything further but just put the bytes into OS required region and let OS do stuff.
...it requires input bytes must be PNG.
I can very much assure you that the input bytes are in PNG, that's not the issue.
It actually looks like Windows does not expect a PNG by the way, so it turns out that's not a requirement for Windows and must just be an arbitrary choice for this library (well maybe not arbitrary, but for a different reason than Windows).
The format that this library uses to store the image in the clipboard is called DIB V5
according to the code here, which is described by Microsoft here.
Which, it turns out, is a bitmap, so it's never going to be my compressed PNG data.
^ I also used Free Clipboard Viewer to confirm that hitting "Print Screen" does store the data in Bitmap, so this is reasonable.
I think I'm going to have to make my screenshots small enough to be pasteable by resizing them instead of compressing them because this format isn't compressable.
I'm gonna mark this one as closed, since it's not an issue with the library.
I'd like to be able to hit "Print Screen" on my keyboard and paste the images into a Steam chat, but as it stands that doesn't work because the screenshots created by Windows are too big in terms of filesize.
I wrote a simple program using this library that uses pngquant to optimize the image data in the clipboard and then replace the clipboard with it, but it doesn't work.
Here's the important code:
and here's the output I see:
As you can see, the compression does work, but when I write that to the clipboard it's replaced with something much larger, often around 2x the original size(!)
It'd be great if the original bytes could be written to the clipboard without being re-encoded (on Windows)