ultralight-ux/Ultralight

Canvas toDataURL() returns empty string

JohnKlenk opened this issue · 0 comments

In UltraLight 1.3 (and also 1.2.1), the toDataURL() canvas function returns an empty string (does not throw exception). Here is example html to show the issue (this works in Chrome) in the UltraLight browser sample:

<html>
<body>
<div id="output"></div>
<script>
// Create a 16 x 16 canvas filled with a color
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
const size = 16;
canvas.width = size;
canvas.height = size;
ctx.fillStyle = "#006575";
ctx.fillRect(0, 0, size, size);

// Call toDataURL() and GetImageData()
let output = "dataURL: " + canvas.toDataURL().length;
try {
  var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
  output += " imageData: " + imageData.data.length;
} catch (error) {
  output += " imageData error: " + error;
}

// Output length of toDataURL() and GetImageData()
document.getElementById('output').textContent = output;
</script>
</body>
</html>

FYI, the getImageData() function was broken in 1.2 (and even caused a freeze if the inspector was open), but has been fixed in 1.3.

Edit: I tried using toBlob() as a workaround, but that also fails.