Perjanjian Pemrosesan dan Keamanan Data
<!-- 2d type canvas --><canvas id="myCanvas" type="2d" style="border: 1px solid; width: 300px; height: 150px;" />
id="myCanvas" to uniquely identify a canvas, which will be used to get the Canvas object later.type to define the type of the canvas, for this example, type="2d" is used.wx.createSelectorQuery().select('#myCanvas') // id in WXML.fields({ node: true, size: true }).exec((res) => {// Canvas Objectconst canvas = res[0].node// rendering contextconst ctx = canvas.getContext('2d')})
wx.createSelectorQuery().select('#myCanvas') // id in WXML.fields({ node: true, size: true }).exec((res) => {// Canvas Objectconst canvas = res[0].node// rendering contextconst ctx = canvas.getContext('2d')// The actual drawing width and height of the Canvas.const width = res[0].widthconst height = res[0].height// Initialise canvas sizeconst dpr = wx.getWindowInfo().pixelRatiocanvas.width = width * dprcanvas.height = height * dprctx.scale(dpr, dpr)})
// Omit the initialisation steps above, the canvas object and ctx rendering context have already been obtained// Empty the canvasctx.clearRect(0, 0, width, height)// Drawing a red squarectx.fillStyle = 'rgb(200, 0, 0)';ctx.fillRect(10, 10, 50, 50);// Drawing Blue Translucent Squaresctx.fillStyle = 'rgba(0, 0, 200, 0.5)';ctx.fillRect(30, 30, 50, 50);
// Omit the initialisation steps above, the canvas object and ctx rendering context are already obtained// The image objectconst image = canvas.createImage()// Image load completion callbackimage.onload = () => {// Draw the image to the canvasctx.drawImage(image, 0, 0)}// Set the image srcimage.src = 'https://open.weixin.qq.com/zh_CN/htmledition/res/assets/res-design-download/icon64_wx_logo.png'
// Omitting the initialisation steps above, the canvas object and the ctx rendering context are already acquired// Drawing a red squarectx.fillStyle = 'rgb(200, 0, 0)';ctx.fillRect(10, 10, 50, 50);// Drawing Blue Translucent Squaresctx.fillStyle = 'rgba(0, 0, 200, 0.5)';ctx.fillRect(30, 30, 50, 50);// Generate Imagewx.canvasToTempFilePath({canvas,success: res => {// Path to the generated image temporary fileconst tempFilePath = res.tempFilePath},})
// Omit the initialisation steps above, the canvas object and the ctx rendering context have already been fetched.const startTime = Date.now()// Frame rendering callbacksconst draw = () => {const time = Date.now()// Calculate the elapsed timeconst elapsed = time - startTime// Calculate the animation positionconst n = Math.floor(elapsed / 3000)const m = elapsed % 3000const dx = (n % 2 ? 0 : 1) + (n % 2 ? 1 : -1) * (m < 2500 ? easeOutBounce(m / 2500) : 1)const x = (width - 50) * dx// Renderingctx.clearRect(0, 0, width, height)ctx.fillStyle = 'rgb(200, 0, 0)';ctx.fillRect(x, height / 2 - 25, 50, 50);// Register for next frame renderingcanvas.requestAnimationFrame(draw)}draw()
Apakah halaman ini membantu?
Anda juga dapat Menghubungi Penjualan atau Mengirimkan Tiket untuk meminta bantuan.
masukan