简体   繁体   English

画布在加载时不绘制图像

[英]canvas does not draw image on load

I started to play with canvas coding and I'm stuck on a (most likely) very easy issue. 我开始使用画布编码,但遇到了一个(很可能是)非常简单的问题。 I have a code which on click lads some image, and I would like to put the image on canvas when it's loaded. 我有一个代码,单击后会叠加一些图像,并且希望在加载图像时将其放在画布上。 When I go to diagnostic tools in Chrome, the pictures get loaded and there is no errors in the console, yet the images do get drawn on the canvas. 当我使用Chrome中的诊断工具时,图片会被加载,并且控制台中没有错误,但图像确实会在画布上绘制。

any ideas why? 有什么想法吗?

    sAlphaF = new Image();
    sAlphaF.src = '/img/sAlpha_'+tbaID+'_f.png';
    sAlphaF.onload = function(){
        var ctxs=gc.getContext("2d");
        ctxs.drawImage(sAlphaF,0,0, gc.width, gc.length);
    };
    tAlphaF = new Image();
    tAlphaF.src = '/img/tAlpha_'+tbaID+'_f.png';
    tAlphaF.onload = function(){
        var ctxt=bc.getContext("2d");
        ctxt.drawImage(tAlphaF,0,0, bc.width, bc.length);
    };

将您的bc.length属性更改为bc.height ;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM