Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将图像存储到“全局”变量中_Javascript_Html_Fabricjs - Fatal编程技术网

Javascript 如何将图像存储到“全局”变量中

Javascript 如何将图像存储到“全局”变量中,javascript,html,fabricjs,Javascript,Html,Fabricjs,我有: 当前图像总是空引用。为什么?事实上,它不会呈现任何东西。 我只是想尝试在某些时候渲染整个场景,但我觉得有点错误 谢谢 将您的调用移动到回调内的.fromURL.@Pointy它可以工作,但我不明白为什么@错误输入读取链接的副本-即.fromURL调用是异步的。在HTTP请求完成之前,调用立即返回。回调在完成后被调用,因此此时映像已准备就绪。 var current_image_; var canvas_; canvas_ = new fabric.Canvas('myid'); can

我有:

当前图像总是空引用。为什么?事实上,它不会呈现任何东西。 我只是想尝试在某些时候渲染整个场景,但我觉得有点错误


谢谢

将您的调用移动到回调内的.fromURL.@Pointy它可以工作,但我不明白为什么@错误输入读取链接的副本-即.fromURL调用是异步的。在HTTP请求完成之前,调用立即返回。回调在完成后被调用,因此此时映像已准备就绪。
var current_image_;
var canvas_;

canvas_ = new fabric.Canvas('myid');
canvas_.renderOnAddRemove = false;


function LoadImage(path)
{
    fabric.Image.fromURL(path, function(oImg) {
        // Something
        current_image_ = oImg;
 });    

    Draw();
}

// Other things

function Draw()
{
    canvas_.clear();
    canvas_.add(current_image_);
    canvas_.renderAll();
}