2
我一直在嘗試使用PIXI進行SVG縮放,但結果並不是我期望的那樣。正如你在圖像中看到的那樣,debian標誌是一個SVG文件,似乎是模糊不清的。我寫我的代碼錯誤:如何使用Pixi進行svg縮放
精製而成https://github.com/kevguy/D3-Svg-Comparison/blob/master/src/components/SvgCompare.vue:
// initialization
this.renderer = new PIXI.Application(800, 600, {backgroundColor: 0x1099bb})
document.getElementById('svg-canvas').appendChild(this.renderer.view)
this.container = new PIXI.Container()
this.stage = this.renderer.stage
this.stage.addChild(this.container)
// appending the svg file
const texture = PIXI.Texture.fromImage(this.chosenImage)
this.svg = new PIXI.Sprite(texture)
this.svg.anchor.x = 0.8
this.svg.anchor.y = 0.8
this.svg.position.x = 400
this.svg.position.y = 300
this.svg.scale.x = this.selectedScale
this.svg.scale.y = this.selectedScale
this.container.addChild(this.svg)
chosenImage
是利用import * as choesnImage from 'the-file-path'
selectedScale
檢索SVG文件是可以動態改變得益於VueJS選擇縮放值- 您可以查看我的作品here及其對應的GitHub repo
- 兔子標誌是爲了驗證縮放發生的時間,它只適用於SVG而不是整個畫布。