提交 28442497 编写于 作者: H hdx

chrod(canvas): 使用新规范获取 devicePixelRatio

上级 d70fdaf3
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<script> <script>
function hidpi(canvas : UniCanvasElement) { function hidpi(canvas : UniCanvasElement) {
const context = canvas.getContext("2d")!; const context = canvas.getContext("2d")!;
const dpr = uni.getSystemInfoSync().pixelRatio; const dpr = uni.getDeviceInfo().devicePixelRatio;
canvas.width = canvas.offsetWidth * dpr; canvas.width = canvas.offsetWidth * dpr;
canvas.height = canvas.offsetHeight * dpr; canvas.height = canvas.offsetHeight * dpr;
context.scale(dpr, dpr); context.scale(dpr, dpr);
......
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
private runningFlag : boolean = false private runningFlag : boolean = false
// #ifdef WEB // #ifdef WEB
private _bindAnimate: Function = null private _animateResult: number = 0
// #endif // #endif
constructor(ctx : CanvasRenderingContext2D) { constructor(ctx : CanvasRenderingContext2D) {
...@@ -106,13 +106,13 @@ ...@@ -106,13 +106,13 @@
if (!this.runningFlag) { if (!this.runningFlag) {
return return
} }
requestAnimationFrame(this._bindAnimate) this._animateResult = requestAnimationFrame(this.animate.bind(this))
// #endif // #endif
} }
start() { start() {
// #ifdef WEB // #ifdef WEB
cancelAnimationFrame(this._bindAnimate) cancelAnimationFrame(this._animateResult)
this.runningFlag = true this.runningFlag = true
this.animate() this.animate()
// #endif // #endif
...@@ -129,7 +129,7 @@ ...@@ -129,7 +129,7 @@
stop() { stop() {
// #ifdef WEB // #ifdef WEB
this.runningFlag = false this.runningFlag = false
cancelAnimationFrame(this._bindAnimate) cancelAnimationFrame(this._animateResult)
// #endif // #endif
// #ifdef APP // #ifdef APP
...@@ -144,7 +144,7 @@ ...@@ -144,7 +144,7 @@
let canvas = uni.getElementById("canvas") as UniCanvasElement let canvas = uni.getElementById("canvas") as UniCanvasElement
let canvasContext = canvas.getContext("2d"); let canvasContext = canvas.getContext("2d");
if (canvasContext != null) { if (canvasContext != null) {
const dpr = uni.getSystemInfoSync().pixelRatio const dpr = uni.getDeviceInfo().devicePixelRatio ?? 1;
canvas.width = canvas.offsetWidth * dpr canvas.width = canvas.offsetWidth * dpr
canvas.height = canvas.offsetHeight * dpr canvas.height = canvas.offsetHeight * dpr
canvasContext.scale(dpr, dpr) canvasContext.scale(dpr, dpr)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册