【问题标题】:How to scale an image in Fabric.js to ignore the aspect ratio?如何在 Fabric.js 中缩放图像以忽略纵横比?
【发布时间】:2021-12-24 21:41:42
【问题描述】:

我正在尝试将木镶板的图像添加到设计为看起来像一个房间的 fabric.js 画布上。我希望木镶板的图像被拉伸并且纵横比被忽略,所以它覆盖了整面墙。但是,图像当前正在被裁剪。在此处查看图片:Image of cropped panelling

有人可以帮帮我吗?

const getPanelling = (hex) => {
  const imageSrc = self.$nuxt.$store.getters['component_data/data']('wallImgURL')

  var filter = new fabric.Image.filters.BlendColor({
    mode: 'overlay',
    alpha: 0.7,
    color: hex
  })

  fabric.Image.fromURL(imageSrc, (image) => {
    image.filters.push(filter)
    image.applyFilters()
    image.type = 'wall'
    canvas.add(image)
    canvas.sendToBack(image)
  }, {
    top: ceilingHeight(),
    height: floorLevel() - ceilingHeight(),
    width: canvas.width,
    backgroundImageStretch: false, 
    crossOrigin: 'anonymous',
    hoverCursor: 'default',
    selectable: false, // make this object not selectable
    originY: 'top',
  })
}

【问题讨论】:

    标签: fabricjs


    【解决方案1】:

    image.width = wall.width * scaleX
    image.height = wall.height * scaleY
    image.top = wall.top
    image.left = wall.left
    canvas.renderAll()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-09
      • 2021-11-24
      • 2015-11-03
      • 2013-03-04
      相关资源
      最近更新 更多