中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
需要在画布上绘制渐变色及网络图片合成起来将图片保存到本地相册。
微信扫码分享
imageSource.createPixelMap(opts, async (err, pixelMap) => { let offScreenCanvas = new OffscreenCanvas(value.size.width, value.size.height); let OffScreenContext = offScreenCanvas.getContext("2d"); this.imageScale = offScreenCanvas.width / display.getDefaultDisplaySync().width; OffScreenContext.drawImage(pixelMap, 0, 0, offScreenCanvas.width, offScreenCanvas.height); //进行图像绘制 let linearGradient = offScreenCanvas.getContext("2d", { antialias: true }).createLinearGradient(50, 0, 300, 0); linearGradient.addColorStop(0.0, '#ff0000'); linearGradient.addColorStop(0.1, '#ffff00'); linearGradient.addColorStop(1.0, '#00ff00'); offScreenCanvas.getContext("2d", { antialias: true }).fillStyle = linearGradient; OffScreenContext.fillRect(30, 30, 100, 100) saveToFile(OffScreenContext.getPixelMap(0, 0, offScreenCanvas.width, offScreenCanvas.height), uri) .then(() => { this.showSuccess(); }); })