代码之家  ›  专栏  ›  技术社区  ›  ajthinking

在Konva层或舞台上使用背景图像

  •  0
  • ajthinking  · 技术社区  · 6 年前

    在使用Konva和VueJS时,如何将背景图像添加到我的舞台或图层? 我试过申请 fillPatternImage 在里面 config 在层和舞台上都没有效果。在文档中找不到任何关于这个的内容,除了在其中一个图层中添加一个大矩形并填充它。有什么办法吗?

    这里有一些代码,我在一个形状上使用它。我可以做一些类似的但在层/组/舞台级别设置背景吗?

    <v-stage
      ref="stage"
      :config="configKonva"
    >
      <v-layer v-if="image" ref="layer">
        <v-regular-polygon
          v-for="item in list"
          :key="item.id"
          :config="{
            x: item.x,
            y: item.y,
            sides: 6,
            rotation: item.rotation,
            id: item.id,
            numPoints: 5,
            radius: 30,
            outerRadius: 50,
            opacity: 0.8,
            fillPatternImage: image,
            fillPatternRepeat: 'no-repeat',
            fillPatternOffset: {
    ...
    
    0 回复  |  直到 6 年前
        1
  •  1
  •   lavrton    6 年前

    stage layer 和 group fillPatternImage 财产。只有形状具有该属性: https://konvajs.org/api/Konva.Shape.html#fillPatternImage

    此外,您还可以将带有CSS的背景图像添加到stage容器中(但是如果您尝试使用Konva方法导出画布内容,则不会将这些背景导出到图像中)