为什么更改画布大小会重置其参数? [英] Why changing canvas size resets its parameters?
问题描述
当我更改画布大小时,我注意到参数'mozImageSmoothingEnabled'正在重置.
When I change the canvas size, I notice the parameter 'mozImageSmoothingEnabled' is being reset.
HTML
<canvas id='canv'>Your browser don't support canvas.</canvas>
JavaScript
Javascript
var cnv = document.getElementById('canv');
var ctx = cnv.getContext('2d');
console.log(ctx.mozImageSmoothingEnabled); // default 'true'
ctx.mozImageSmoothingEnabled = false;
console.log(ctx.mozImageSmoothingEnabled); // shows 'false'
cnv.width = 100;
console.log(ctx.mozImageSmoothingEnabled); // shows 'true'
JSFiddle: https://jsfiddle.net/epvtuz37/
JSFiddle: https://jsfiddle.net/epvtuz37/
这是错误,还是预期的行为?
Is this a bug, or expected behavior?
推荐答案
由于更改画布width
或height
参数时,附加上下文的每个属性均重置为其默认值
Because when you change the canvas width
or height
parameters, every properties of the attached context are reset to their default.
在创建canvas元素时,随后每当设置width和height属性(无论是新值还是之前的值)时,都必须将位图和任何关联的上下文清除回其初始状态,并使用新指定的坐标空间尺寸.
When the canvas element is created, and subsequently whenever the width and height attributes are set (whether to a new value or to the previous value), the bitmap and any associated contexts must be cleared back to their initial state and reinitialized with the newly specified coordinate space dimensions.
这篇关于为什么更改画布大小会重置其参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!