我有这个angularJS应用程序,我从画布生成图像。我有一切工作,我甚至可以从HTML中的SVG绘制图像,但试图从相对URL拉图像无法显示。 我知道图像正在加载,并且由于某些控制台日志记录,它实际上找到了正确的图像。HTML画布绘制图像不起作用
这里是我的选项对象:
// Define our options
self.options = {
team: null,
itemsPerRow: 3,
targets: {
containerId: 'totals',
svgContainerClassName: 'total-item',
svgClassName: 'svg-document',
svgTitleClassName: 'total-title'
},
itemPadding: {
top: 50,
right: 50,
bottom: 100,
left: 50
},
canvasPadding: {
top: 300,
right: 100,
bottom: 200,
left: 100
},
sizes: {
first: 1100,
all: 300
},
footer: {
logo: '/assets/images/k-logo-orange-black.png'
}
};
你可以看到页脚标志。 用于显示的功能是这样的:
// Private function to draw the footer
var drawFooter = function (canvas, ctx) {
var y = canvas.height - 50;
// Draw our image
var img = new Image();
img.onload = function() {
console.log(img.width);
console.log(img.height);
console.log(canvas.width - self.options.canvasPadding.right - img.width);
console.log(y - img.height);
ctx.drawImage(img, canvas.width - self.options.canvasPadding.right - img.width, y - img.height);
};
img.src = self.options.footer.logo;
};
所以,控制台日志输出图像的尺寸和位置的帆布也都是我的画布的范围内,但图像只是没有显示。 有谁知道为什么?
你可以在某个地方创建一个实例,jsfiddle或其他东西? – CBroe
很难做到,但我会给它一个镜头 – r3plica