Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.

Conversation

@elvinn
Copy link

@elvinn elvinn commented Aug 29, 2021

背景:因为 wxml-to-canvas 不支持渐变色背景,所以希望在调用 renderToCanvas 之前,能够允许业务方自行对 canvas 进行一些绘制。然后目前 renderToCanvas 会清空 canvas 画布,导致业务方自行绘制的数据失效,因为增加 shouldClearRect 进行配置。

绘制渐变色背景图例子:

const { ctx } = this.wxmlToCanvasWidget;
// wxml-to-canvas 不支持渐变背景色,自行实现
  ctx.save();
  const {
    canvasHeight,
    canvasWidth,
  } = this.data;
  const grd = ctx.createLinearGradient(0, 0, 0, canvasHeight);
  grd.addColorStop(0, '#FF6E55');
  grd.addColorStop(1, '#EB4225');

  ctx.fillStyle = grd;
  ctx.fillRect(0, 0, canvasWidth, canvasHeight);
  ctx.restore();

  this.wxmlToCanvasWidget.renderToCanvas({
    wxml,
    style,
    shouldClearRect: false,
  }).then((res) => { ... });

@elvinn elvinn changed the title feat: 增加 shouldClearRect 配置,允许在绘制前不清空 canvas 增加 shouldClearRect 配置,允许在绘制前不清空 canvas Aug 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant