Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
c3e5cb5c
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6005
Star
91
Fork
164
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
c3e5cb5c
编写于
8月 12, 2024
作者:
H
hdx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
canvas: 调整布局,将测试结果移动到底部
上级
b249c9c7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
49 addition
and
54 deletion
+49
-54
pages/component/canvas/canvas.uvue
pages/component/canvas/canvas.uvue
+49
-54
未找到文件。
pages/component/canvas/canvas.uvue
浏览文件 @
c3e5cb5c
<template>
<view class="page" id="page-canvas">
<canvas id="canvas" class="canvas-element"></canvas>
<scroll-view class="scroll-view">
<!-- #ifdef WEB -->
<button class="canvas-drawing-button" @click="canvasToBlob">canvasToBlob</button>
<view>
<text style="padding: 8px 10px;">获取 CanvasContext</text>
<text>testToBlobResult: {{testToBlobResult}}</text>
</view>
<!-- #endif -->
<button class="canvas-drawing-button" id="toDataURL" @click="canvasToDataURL">canvasToDataURL</button>
<view class="text-group" v-if="dataBase64.length>0">
<text>canvasToDataURL:</text>
<text>{{dataBase64.slice(0,22)}}...</text>
</view>
<button @click="onCreateImage">createImage</button>
<button @click="onCreatePath2D">createPath2D</button>
<button @click="startAnimationFrame">requestAnimationFrame</button>
<button @click="stopAnimationFrame">cancelAnimationFrame</button>
<view style="padding: 8px 10px;">CanvasContext API 演示</view>
<navigator url="./canvas-context">
<button>CanvasContext API</button>
</navigator>
<view class="text-group">
<text>获取 CanvasContext 结果:</text>
<text id="testCanvasContext">{{testCanvasContext}}</text>
...
...
@@ -24,27 +40,6 @@
<text>测试 createPath2D 结果:</text>
<text id="testCreatePath2D">{{testCreatePath2D}}</text>
</view>
<!-- #ifdef WEB -->
<button class="canvas-drawing-button" @click="canvasToBlob">canvasToBlob</button>
<view>
<text>testToBlobResult: {{testToBlobResult}}</text>
</view>
<!-- #endif -->
<button class="canvas-drawing-button" id="toDataURL" @click="canvasToDataURL">canvasToDataURL</button>
<view class="text-group" v-if="dataBase64.length>0">
<text>canvasToDataURL:</text>
<text>{{dataBase64.slice(0,22)}}...</text>
</view>
<button @click="onCreateImage">createImage</button>
<button @click="onCreatePath2D">createPath2D</button>
<button @click="startAnimationFrame">requestAnimationFrame</button>
<button @click="stopAnimationFrame">cancelAnimationFrame</button>
<view style="padding: 8px 10px;">CanvasContext API 演示</view>
<navigator url="./canvas-context">
<button>CanvasContext API</button>
</navigator>
</scroll-view>
</view>
</template>
...
...
@@ -67,9 +62,9 @@
renderingContext: null as CanvasRenderingContext2D | null,
canvasWidth: 0,
canvasHeight: 0,
dataBase64: '',
taskId: 0,
lastTime: 0,
dataBase64: '',
taskId: 0,
lastTime: 0,
frameCount: 0,
// 仅测试
testCanvasContext: false,
...
...
@@ -94,7 +89,7 @@
hidpi(this.canvas!);
this.canvasWidth = this.canvas!.width;
this.canvasHeight = this.canvas!.height;
this.canvasHeight = this.canvas!.height;
// #ifdef WEB
context.toBlob((blob : Blob) => {
...
...
@@ -113,11 +108,11 @@
// this.canvas = canvas;
// this.canvasWidth = canvas.width;
// this.canvasHeight = canvas.height;
},
onUnload() {
if (this.taskId > 0) {
this.stopAnimationFrame()
}
},
onUnload() {
if (this.taskId > 0) {
this.stopAnimationFrame()
}
},
methods: {
// #ifdef WEB
...
...
@@ -130,7 +125,7 @@
canvasToDataURL() {
this.dataBase64 = this.canvasContext!.toDataURL()
},
onCreateImage() {
onCreateImage() {
this.renderingContext!.clearRect(0, 0, this.canvasWidth, this.canvasHeight)
let image = this.canvasContext!.createImage();
image.src = "../../static/logo.png"
...
...
@@ -159,27 +154,27 @@
path2D.bezierCurveTo(x2, y2, x3, y3, x4, y4);
}
context.stroke(path2D);
},
startAnimationFrame() {
this.taskId = this.canvasContext!.requestAnimationFrame((timestamp : number) => {
this.testFrameCount++
this.updateFPS(timestamp)
this.startAnimationFrame()
})
},
stopAnimationFrame() {
this.canvasContext!.cancelAnimationFrame(this.taskId)
this.taskId = 0
},
updateFPS(timestamp : number) {
this.frameCount++
if (timestamp - this.lastTime >= 1000) {
const timeOfFrame = (1000 / this.frameCount)
this.renderingContext!.clearRect(0, 0, this.canvasWidth, this.canvasHeight)
this.renderingContext!.fillText(`${this.frameCount} / ${timeOfFrame.toFixed(3)}ms`, 10, 18)
this.frameCount = 0
this.lastTime = timestamp
}
},
startAnimationFrame() {
this.taskId = this.canvasContext!.requestAnimationFrame((timestamp : number) => {
this.testFrameCount++
this.updateFPS(timestamp)
this.startAnimationFrame()
})
},
stopAnimationFrame() {
this.canvasContext!.cancelAnimationFrame(this.taskId)
this.taskId = 0
},
updateFPS(timestamp : number) {
this.frameCount++
if (timestamp - this.lastTime >= 1000) {
const timeOfFrame = (1000 / this.frameCount)
this.renderingContext!.clearRect(0, 0, this.canvasWidth, this.canvasHeight)
this.renderingContext!.fillText(`${this.frameCount} / ${timeOfFrame.toFixed(3)}ms`, 10, 18)
this.frameCount = 0
this.lastTime = timestamp
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录