以下是来自的示例Konvajs http://konvajs.github.io/docs/shapes/Image.html加载图像的库:
var imageObj = new Image();
imageObj.onload = function() {
var yoda = new Konva.Image({
x: 50,
y: 50,
image: imageObj,
width: 106,
height: 118
});
And here is my code
var annotation = new Konva.Line({
points: this.contour,
stroke: color,
closed: true,
strokeWidth: 1
});
var nativeImageObject = new Image();
nativeImageObject.onload = function() {
var konvaImage = new Konva.Image({
image: nativeImageObject
});
annotation.fillPatternImage(konvaImage);
DentalChart.Pattern.customPatternImages.push(customPatternImage);
gridLayer.add(annotation);
stage.draw();
};
nativeImageObject.src = pattern.toDataURL();
nativeImageObject.id = patternEnum + '' + color;
为什么它继续记录未捕获的类型错误:无法在“CanvasRenderingContext2D”上执行“createPattern”:提供的值不是“(HTMLImageElement或HTMLVideoElement或HTMLCanvasElement或ImageBitmap)”类型
Call Stack Trace:
console.trace()
(anonymous function) @ VM11965:1evaluate @ (program):493
InjectedScript._evaluateOn @ VM11739:875
InjectedScript._evaluateAndWrap @ VM11739:808InjectedScript.evaluateOnCallFrame @ VM11739:933
Konva.Context.createPattern @ konva.js:1805Konva.SceneContext._fillPattern @ konva.js:1987
Konva.SceneContext._fill @ konva.js:2045Konva.Context.fillStrokeShape @ konva.js:1635
Konva.Line._sceneFunc @ konva.js:12613Konva.Util.addMethods.drawScene @ konva.js:7997
(anonymous function) @ konva.js:7675Konva.Collection.each @ konva.js:664
Konva.Util.addMethods._drawChildren @ konva.js:7674
Konva.Util.addMethods.drawScene @ konva.js:7629
Konva.Util.addMethods.drawScene @ konva.js:10363
(anonymous function) @ konva.js:7675
Konva.Collection.each @ konva.js:664
Konva.Util.addMethods._drawChildren @ konva.js:7674
Konva.Util.addMethods.drawScene @ konva.js:7629
Konva.Util.addMethods.draw @ konva.js:3799
Konva.Util.addMethods.draw @ konva.js:9337(anonymous function) @ DentalChartLib.js:132DentalChart.Pattern.getCustomPattern.nativeImageObject.onload @ DentalChartLib.js:617
undefined
For fillPatternImage
使用本机Image
object.
http://konvajs.github.io/docs/styling/Fill.html http://konvajs.github.io/docs/styling/Fill.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)