提交 03903c81 编写于 作者: H hdx

canvas: 调整获取 devicePixelRatio 方式

上级 02ff8d6d
...@@ -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.getDeviceInfo().devicePixelRatio ?? 1; const dpr = uni.getWindowInfo().pixelRatio ?? 1;
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);
......
...@@ -190,7 +190,7 @@ ...@@ -190,7 +190,7 @@
const renderingContext = context.getContext('2d')!; const renderingContext = context.getContext('2d')!;
const canvas = renderingContext.canvas; const canvas = renderingContext.canvas;
const dpr = uni.getDeviceInfo().devicePixelRatio ?? 1; const dpr = uni.getWindowInfo().pixelRatio ?? 1;
canvas.width = canvas.offsetWidth * dpr canvas.width = canvas.offsetWidth * dpr
canvas.height = canvas.offsetHeight * dpr canvas.height = canvas.offsetHeight * dpr
renderingContext.scale(dpr, dpr) renderingContext.scale(dpr, dpr)
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
this.renderingContext = context.getContext('2d')!; this.renderingContext = context.getContext('2d')!;
const canvas = this.renderingContext!.canvas; const canvas = this.renderingContext!.canvas;
const dpr = uni.getDeviceInfo().devicePixelRatio ?? 1; const dpr = uni.getWindowInfo().pixelRatio ?? 1;
canvas.width = canvas.offsetWidth * dpr canvas.width = canvas.offsetWidth * dpr
canvas.height = canvas.offsetHeight * dpr canvas.height = canvas.offsetHeight * dpr
this.renderingContext!.scale(dpr, dpr) this.renderingContext!.scale(dpr, dpr)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册