- HTML 画布教程
- HTML 画布 - 主页
- HTML 画布 - 简介
- 环境设置
- HTML 画布 - 第一个应用程序
- HTML 画布 - 绘制二维形状
- HTML 画布 - 路径元素
- 使用路径元素绘制二维形状
- HTML 画布 - 颜色
- HTML 画布 - 添加样式
- HTML 画布 - 添加文本
- HTML 画布 - 添加图像
- HTML 画布 - 画布时钟
- HTML 画布 - 变换
- 合成和裁剪
- HTML 画布 - 基本动画
- 高级动画
- HTML 画布 API 函数
- HTML 画布 - 元素
- HTML 画布 - 矩形
- HTML 画布 - 线条
- HTML 画布 - 路径
- HTML 画布 - 文本
- HTML 画布 - 颜色和样式
- HTML 画布 - 图像
- HTML 画布 - 阴影和变换
- HTML 画布实用资源
- HTML 画布 - 快速指南
- HTML 画布 - 实用资源
- HTML 画布 - 讨论
HTML 画布 - imageSmoothingQuality 属性
HTML 画布的 imageSmoothingQuality 属性可以通过 Canvas 2D API 用来设置图像平滑质量。
可能的输入值
属性接受的值如下 -
| 序号 | 值 & 描述 |
|---|---|
| 1 | 低 品质设置为低. |
| 2 | 中 品质设置为中. |
| 3 | 高 品质设置为高. |
示例
以下示例采用图像并使用属性 HTML 画布 imageSmoothingQuality 属性应用低平滑质量。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Reference API</title>
<style>
body {
margin: 10px;
padding: 10px;
}
</style>
</head>
<body>
<canvas id="canvas" width="400" height="200" style="border: 1px solid black;background-color: grey;"></canvas>
<script>
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
const image = new Image()
image.src = 'https://tutorialspoint.com/images/logo.png';
context.imageSmoothingQuality = 'low';
context.drawImage(image, 25, 20, 300, 150);
</script>
</body>
</html>
输出
上述代码在网页上返回的输出如下 -
示例
对于以下示例,通过使用属性 imageSmoothingQuality 将平滑质量设置为中,在画布元素上呈现图像。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Reference API</title>
<style>
body {
margin: 10px;
padding: 10px;
}
</style>
</head>
<body>
<canvas id="canvas" width="400" height="200" style="border: 1px solid black;background-color: grey;"></canvas>
<script>
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
const image = new Image()
image.src = 'https://tutorialspoint.com/images/logo.png';
context.imageSmoothingQuality = 'medium';
context.drawImage(image, 25, 20, 300, 150);
</script>
</body>
</html>
输出
上述代码在网页上返回的输出如下 -
示例
以下示例通过使用属性 imageSmoothingQuality 为画布元素内的图像对象设置高图像平滑质量。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Reference API</title>
<style>
body {
margin: 10px;
padding: 10px;
}
</style>
</head>
<body>
<canvas id="canvas" width="400" height="200" style="border: 1px solid black;background-color: grey;"></canvas>
<script>
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
const image = new Image()
image.src = 'https://tutorialspoint.com/images/logo.png';
context.imageSmoothingQuality = 'high';
context.drawImage(image, 25, 20, 300, 150);
</script>
</body>
</html>
输出
上述代码在网页上返回的输出如下 -
html_canvas_images.htm
广告