为什么 jCanvas 在 canvas 的小尺寸上绘制质量差的圆圈
Why jCanvas draws poor quality circle on small sizes of canvas
只想说,我不使用CSS,但在小尺寸canvas圆圈质量很差。
示例:jcanvas <a href="https://jsfiddle.net/tkdn2rv6/25/" rel="nofollow noreferrer">https://jsfiddle.net/tkdn2rv6/25/</a>
例如,konvajs 上一切正常:konva <a href="https://jsfiddle.net/qup9s57y/23/" rel="nofollow noreferrer">https://jsfiddle.net/qup9s57y/23/</a>
为什么图像这么模糊?
我想用jcanvas,因为它比较小,所以用jQuery.
我试图通过将两者放入一个通用代码段来重现您的问题,并且质量看起来相同:
$('#canvas').drawArc({
x: 20, y: 20, radius: 15, strokeStyle: '#000', strokeWidth: 1,
});
var circle = new Konva.Circle({
x: 20, y: 20, radius: 15, stroke: '#000', strokeWidth: 1
});
var layer = new Konva.Layer().add(circle);
new Konva.Stage({container: 'container', width: 40, height: 40}).add(layer);
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jcanvas/21.0.1/min/jcanvas.min.js"></script>
<script src="https://cdn.rawgit.com/konvajs/konva/2.2.1/konva.min.js"></script>
<div id="container"></div>
<canvas id="canvas"></canvas>
您必须使用 detectPixelRatio
解决方案:
$('canvas').detectPixelRatio(function(ratio) {
$('#canvas').drawArc({
x: 20, y: 20, radius: 15, strokeStyle: '#000', strokeWidth: 1,
});
});
var circle = new Konva.Circle({
x: 20, y: 20, radius: 15, stroke: '#000', strokeWidth: 1
});
var layer = new Konva.Layer().add(circle);
new Konva.Stage({container: 'container', width: 40, height: 40}).add(layer);
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jcanvas/21.0.1/min/jcanvas.min.js"></script>
<script src="https://cdn.rawgit.com/konvajs/konva/2.2.1/konva.min.js"></script>
<div id="container"></div>
<canvas id="canvas"></canvas>
只想说,我不使用CSS,但在小尺寸canvas圆圈质量很差。
示例:jcanvas <a href="https://jsfiddle.net/tkdn2rv6/25/" rel="nofollow noreferrer">https://jsfiddle.net/tkdn2rv6/25/</a>
例如,konvajs 上一切正常:konva <a href="https://jsfiddle.net/qup9s57y/23/" rel="nofollow noreferrer">https://jsfiddle.net/qup9s57y/23/</a>
为什么图像这么模糊?
我想用jcanvas,因为它比较小,所以用jQuery.
我试图通过将两者放入一个通用代码段来重现您的问题,并且质量看起来相同:
$('#canvas').drawArc({
x: 20, y: 20, radius: 15, strokeStyle: '#000', strokeWidth: 1,
});
var circle = new Konva.Circle({
x: 20, y: 20, radius: 15, stroke: '#000', strokeWidth: 1
});
var layer = new Konva.Layer().add(circle);
new Konva.Stage({container: 'container', width: 40, height: 40}).add(layer);
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jcanvas/21.0.1/min/jcanvas.min.js"></script>
<script src="https://cdn.rawgit.com/konvajs/konva/2.2.1/konva.min.js"></script>
<div id="container"></div>
<canvas id="canvas"></canvas>
您必须使用 detectPixelRatio 解决方案:
$('canvas').detectPixelRatio(function(ratio) {
$('#canvas').drawArc({
x: 20, y: 20, radius: 15, strokeStyle: '#000', strokeWidth: 1,
});
});
var circle = new Konva.Circle({
x: 20, y: 20, radius: 15, stroke: '#000', strokeWidth: 1
});
var layer = new Konva.Layer().add(circle);
new Konva.Stage({container: 'container', width: 40, height: 40}).add(layer);
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jcanvas/21.0.1/min/jcanvas.min.js"></script>
<script src="https://cdn.rawgit.com/konvajs/konva/2.2.1/konva.min.js"></script>
<div id="container"></div>
<canvas id="canvas"></canvas>