收藏
回答

canvas组件在不填充颜色的情况下,安卓手机上背景色为黑色,ios为白色

框架类型 问题类型 终端类型 微信版本 基础库版本
小程序 Bug 微信安卓客户端 7.0.81 3.8.10

使用canvas做透明渐变,ios上正常,安卓手机上,背景色越透明,黑色越明显

回答关注问题邀请回答
收藏

3 个回答

  • 慢慢。
    慢慢。
    07-16

    https://developers.weixin.qq.com/community/develop/doc/000c0ef4548670076393518396b800


    07-16
    有用
    回复
  • 旧时光°
    旧时光°
    07-10

    遇到问题+1

    07-10
    有用
    回复
  • 袁子武器🚀
    袁子武器🚀
    07-10
    // index.wxml
    <view class="container">
      <canvas id="myCanvas" type="2d" />
    </view>
    
    // index.js
    const app = getApp()
    Page({
        data: {
    
    
        },
        onLoad: function() {
          wx.createSelectorQuery()
              .select('#myCanvas') // 在 WXML 中填入的 id
              .node(({ node: canvas }) => {
                  const context = canvas.getContext('2d')
    
    
                  // 填充背景色
                  context.fillStyle = 'rgb(255, 255, 255)'
                  context.fillRect(10, 10, 150, 80)
    
    
                  // Create linear gradient
                  const grd = context.createLinearGradient(0, 0, 200, 0)
                  grd.addColorStop(0, 'rgba(218, 230, 253, 1)')
                  grd.addColorStop(1, 'rgba(255, 255, 255, 0)')
    
    
                  // Fill with gradient
                  context.fillStyle = grd
                  context.fillRect(10, 10, 150, 80)
              })
              .exec()
        },
    })
    
    07-10
    有用
    回复
登录 后发表内容