--- title: image-rendering slug: Web/CSS/image-rendering tags: - CSS - CSS图像 - CSS属性 - 图像 translation_of: Web/CSS/image-rendering ---
CSS 属性 image-rendering 用于设置图像缩放算法。它适用于元素本身,适用于元素其他属性中的图像,也应用于子元素。
The {{Glossary("user agent")}} will scale an image when the page author specifies dimensions other than its natural size. Scaling may also occur due to user interaction (zooming). 举个例子,如果有一张尺寸为 100×100px 的图片,但作者有意将尺寸设置为 200×200px(或50×50px),然后,图片便会根据 image-rendering 指定的算法,缩小或放大到新尺寸。此属性对于未缩放的图像没有影响。
Note: The Canvas API can provide a fallback solution for crisp-edges through manual image data manipulation.
/* 专有属性值 */ image-rendering: auto; image-rendering: crisp-edges; image-rendering: pixelated; /* 全局属性值 */ image-rendering: inherit; image-rendering: initial; image-rendering: unset;
autosmooth {{Experimental_Inline}}high-quality {{Experimental_Inline}}smooth, but with a preference for higher-quality scaling. If system resources are constrained, images with high-quality should be prioritized over those with any other value, when considering which images to degrade the quality of and to what degree.crisp-edgespixelatedauto 相同。注意:The values optimizeQuality and optimizeSpeed present in an early draft (and coming from its SVG counterpart) are defined as synonyms for the smooth and pixelated values respectively.
<div> <img class="auto" alt="auto" src="https://mdn.mozillademos.org/files/2765/blumen.jpg" /> <img class="pixelated" alt="pixelated" src="https://mdn.mozillademos.org/files/2765/blumen.jpg" /> <img class="crisp-edges" alt="crisp-edges" src="https://mdn.mozillademos.org/files/2765/blumen.jpg" /> </div>
img {
height: 200px;
}
.auto {
image-rendering: auto;
}
.pixelated {
-ms-interpolation-mode: nearest-neighbor;
image-rendering: pixelated;
}
.crisp-edges {
image-rendering: -webkit-optimize-contrast;
image-rendering: crisp-edges;
}
{{EmbedLiveSample('Examples')}}
| 规范 | 状态 | 备注 |
|---|---|---|
| {{SpecName("CSS3 Images", "#the-image-rendering", "image-rendering")}} | {{Spec2("CSS3 Images")}} | Initial definition. |
{{cssinfo}}
注意:虽然在最初此属性与 SVG 的 image-rendering 属性定义相近, 但到现在,它们之间已有相当的差别。
{{Compat("css.properties.image-rendering")}}
译者注:这是来自旧版浏览器兼容性表格的备注,保留以便查阅。可另行参阅 Can I use。
Internet Explorer 7 和 8 支持非标准的 -ms-interpolation-mode 属性,有两个属性值:bicubic 和 nearest-neighbor,和大量差距:
<img> 等元素带的图片 nearest-neighbor (低质量) bicubic (高质量)WebKit 支持一个非标准属性: -webkit-optimize-contrast.
WebKit Nightly 支持,见 bug
Canvas 可以通过人工方式支持 crisp-edge/optimize-contrast 属性.