dntzhang / cax

Canvas 渲染引擎,支持 SVG,兼容了小程序、小游戏和 Web

Home Page:https://dntzhang.github.io/cax

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

小程序 cax 渲染svg里边的image drawImage绘制图像的宽度和高度没有按照传入的图片width height绘制

gexin1 opened this issue · comments

commented
//cax/packages/cax/src/render/display/bitmap.js
 //22 行
        util.getImageInWx(img, (result) => {
          this.img = result.img
          if (!this.rect) {
            this.rect = [0, 0, result.width, result.height]
          }
        // 这里把传入的宽 高 设置为图片的宽高
        // 预期不应该修改传入的图片宽高
          this.width = result.width
          this.height = result.height
          onLoad && onLoad.call(this)
          Bitmap.cache[img] = result
        })
    
//cax/packages/cax/src/render/render/canvas-render.js
//122 行
ctx.drawImage(o.img, bRect[0], bRect[1], bRect[2], bRect[3], 0, 0, bRect[2], bRect[3])
// 预期应该按照传入的宽高裁剪
ctx.drawImage(o.img, bRect[0], bRect[1], bRect[2], bRect[3], 0, 0, this.width, this.height)
commented

请问一下是出于什么方面考虑的呢😥

commented

今晚也遇到这个问题,才代码来看,bitmap和Sprite都是以图片实际尺寸大小去渲染的,想控制展示时的大小,只能通过放大缩小了。