Having trouble loading a canvas-generated image in Chrome (it works fine in Firefox).
"Failed to execute 'texImage2D' on 'WebGLRenderingContext': The cross-origin image at blob:*** could not be loaded.
I've managed to make it work with other images, but the problem arises when I use an SVG for HTML-rendered text. For example, check out this link.
The usual security measures like img.crossOrigin = "*"
or
THREE.ImageUtils.crossOrigin = '*'
are not solving the issue. Any suggestions on how to resolve this?
Here is the code snippet:
$("body").append('<canvas id="canvas" style="border:2px solid black;" width="200" height="200"></canvas>');
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var data = '<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200">' +
'<foreignObject width="100%" height="100%">' +
'<div xmlns="http://www.w3.org/1999/xhtml" style="font-size:40px">' +
html +
'</div>' +
'</foreignObject>' +
'</svg>';
var DOMURL = window.URL || window.webkitURL || window;
var img = new Image();
var svg = new Blob([data], {type: 'image/svg+xml;charset=utf-8'});
svg.crossOrigin = "*";
var url = DOMURL.createObjectURL(svg);
img.onload = function () {
ctx.drawImage(img, 0, 0);
THREE.ImageUtils.crossOrigin = '*';
var texture = THREE.ImageUtils.loadTexture(url);
texture.needsUpdate = true;
var posterText = new THREE.Mesh(
new THREE.BoxGeometry(img.naturalWidth, img.naturalHeight,1),
new THREE.MeshPhongMaterial({
map: texture,
transparent: true
})
);
DOMURL.revokeObjectURL(url);
};
img.crossOrigin = "*";
img.src = url;