Why I cannot use Konva.Image() in Konva.Shape.fillPatternImage(imageObj)?

梦想与她 提交于 2021-02-18 18:11:04

问题


The following is an example from Konvajs library to load an image:

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;

  

回答1:


For fillPatternImage use native Image object.

http://konvajs.github.io/docs/styling/Fill.html



来源:https://stackoverflow.com/questions/34658539/why-i-cannot-use-konva-image-in-konva-shape-fillpatternimageimageobj

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!