Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.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 KineticJS ToImageWidth和Height问题_Javascript_Html_Kineticjs - Fatal编程技术网

Javascript KineticJS ToImageWidth和Height问题

Javascript KineticJS ToImageWidth和Height问题,javascript,html,kineticjs,Javascript,Html,Kineticjs,我遇到了这个奇怪的问题。。!我有一个kineticJS文本元素,我正在将其转换为图像。。这是密码 var simpleText = new Kinetic.Text({ x: 50, y: 50, text: $("#text").val(), fontSize: $("#fontSize").val(), fontFamily: $("#fontName").val(), fill: $("#fontColor").val(), }); var

我遇到了这个奇怪的问题。。!我有一个kineticJS文本元素,我正在将其转换为图像。。这是密码

var simpleText = new Kinetic.Text({
    x: 50,
    y: 50,
    text: $("#text").val(),
    fontSize: $("#fontSize").val(),
    fontFamily: $("#fontName").val(),
    fill: $("#fontColor").val(),
});

var twidth = simpleText.getWidth();
var theight = simpleText.getHeight();

simpleText.toImage({
    width:twidth,
    height:theight,
    callback: function(img){
        var textImg = new Kinetic.Image({
            image: img,
            x: 0,
            y: 0,
            width: twidth,
            height: theight,
            name: 'image',
            stroke: 'red',
            strokeWidth: 2,
            strokeEnabled: false
        });

        addElement(textImg, textImg.getWidth(), textImg.getHeight());
    }
});
所以问题就存在于这里

var twidth = simpleText.getWidth();
var theight = simpleText.getHeight();
如果我只是把宽度和高度放在数字形式中,一切正常,文本被转换,就像这样

var twidth = 500;
var theight = 100;
但是如果我使用simpleText.getWidth()和simpleText.getHeight(),什么也不会发生,图像被创建了,但它没有该文本。正如我在文档中看到的,宽度和高度是toImage()的可选参数,所以我现在删除了,但现在它显示了此错误

未捕获的TypeError:无法读取未定义的属性“bufferCanvas” kinetic.js:28 kinetic.Node.toDataURL kinetic.js:28 Kinetic.Node.ToImageKinetic.js:28添加文本画布.js:83(匿名 函数)canvas.js:352 f.event.dispatch jquery.min.js:3 h.handle.i


你知道我的代码有什么问题吗?

我不是舒尔,这是错误还是功能。但问题是:图片是从这个坐标为:{x:0y:0}的矩形上拍摄的;宽度和高度-作为图像参数插入的内容。(右二)

但是文本有坐标{x:50,y:50}。所以它在上面的“图片”矩形外。 正如你所说,如果你增加宽度和高度:

var twidth = 500;
var theight = 100;
一切都很好,你们会看到文字,但图像将是大的空白

所以。。。只需在toImage函数中插入“x”和“y”参数:

simpleText.toImage({
    width:twidth,
    height:theight,
    x : 50,
    y : 50,
    callback: function(img){
        $('body').append($(img));
    }
});
例如: