为什么更改画布大小会重置其参数? [英] Why changing canvas size resets its parameters?

查看:110
本文介绍了为什么更改画布大小会重置其参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我更改画布大小时,我注意到参数'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?

推荐答案

由于更改画布widthheight参数时,附加上下文的每个属性均重置为其默认值

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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆