We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

CanvasRenderingContext2D.imageSmoothingQuality

这篇翻译不完整。请帮忙从英语翻译这篇文章

这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。

CanvasRenderingContext2D.imageSmoothingQuality 是 Canvas 2D API, 用于设置图像平滑度的属性。

语法

ctx.imageSmoothingQuality = value
value = ctx.imageSmoothingQuality

选项

value
"low","medium","high"

示例

使用 imageSmoothingQuality 属性

这是一段简单的代码片段,对缩放的图片使用 imageSmoothingQuality 属性。

HTML

<canvas id="canvas"></canvas>

JavaScript

var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");

var img = new Image();
img.src = 'https://mdn.mozillademos.org/files/222/Canvas_createpattern.png';
img.onload = function() {
 ctx.mozImageSmoothingEnabled = false;
 ctx.imageSmoothingQuality = "Medium";
 ctx.webkitImageSmoothingEnabled = false;
 ctx.msImageSmoothingEnabled = false;
 ctx.imageSmoothingEnabled = false;
 ctx.drawImage(img, 0, 0, 400, 200);
};

编辑下面代码,在线查看 Canvas 的变化:

规范

Specification Status Comment
HTML Living Standard
imageSmoothingQuality
Living Standard Initial definition.

浏览器兼容性

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 54.0 ? ? 41 ?
Feature Android Android Webview Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support ? 54.0 ? ? 41 ? 54.0

参见

文档标签和贡献者

此页面的贡献者: gabyliu
最后编辑者: gabyliu,