【canvas】--------------处理canvas物理像素模糊问题-------------【劉】

js代码:
var
canvas = document.getElementById('canvas'); var ctx = canvas.getContext('2d'); // Set display size (css pixels). var size = 200; canvas.style.width = size + "px"; canvas.style.height = size + "px"; // Set actual size in memory (scaled to account for extra pixel density). var scale = window.devicePixelRatio; // <--- Change to 1 on retina screens to see blurry canvas. canvas.width = size * scale; canvas.height = size * scale; // Normalize coordinate system to use css pixels. ctx.scale(scale, scale); ctx.fillStyle = "#bada55"; ctx.fillRect(10, 10, 300, 300); ctx.fillStyle = "#ffffff"; ctx.font = '18px Arial'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; var x = size / 2; var y = size / 2; var textString = "I love MDN"; ctx.fillText(textString, x, y);

 

posted @ 2019-03-12 17:36  花果山府邸  阅读(236)  评论(0编辑  收藏  举报