Closed friksa closed 6 years ago
Hi, can you try to send an ArrayBuffer as a frame? That would be newData.data.buffer in your case.
This buffer is 160x46 buffer.zip
Did you try to give it an ArrayBuffer instead of ArrayBufferView?
Not sure I understand the question. This is how I get the buffer. var newData = context.getImageData(0, 0, w, h);
Then, you need to call
var bin = UPNG.encode([newData.data.buffer], w, h, 0);
You called it. After testing, it seems that was the issue. Curious that it worked pretty well most of the time for non 0 color values.
It might help others too by documenting how to take content from a canvas and encode it to PNG using this library.
Thanks again for a great library!!
Ok thank you for the donation! btw. you are the first person to donate to UPNG.js :)
That's a bummer since this is such a great library. At least you know donations work now :)
You're welcome.
PNG encoding sometimes fails... This is an example that frequently fails: var bin = UPNG.encode([newData.data], w, h, 0);
Using 256 colors instead of 0 (unlimited) mostly works, but not always.
This is an example that failed with 0 (unlimited colors) - resulting PNG at: https://x1.gatherworks.com:443/doc/572BD2A2CCA63DBA5EB3C21DE115908B/ffa002be102547399238a7af4a8b3e6f.png
Attaching a screen shot of the application window that was PNG encoded.
I am not sure what the best way is to give you a recreatable example since it depends on the contents of the buffer... but it frequently happens when using 0 (unlimited colors). Encoding mostly works when using this instead (but not always): var bin = UPNG.encode([newData.data], w, h, 0, null, true);