> For AI agents: the complete documentation index is available at /next/zh/llms.txt, the full documentation bundle is available at /next/zh/llms-full.txt.

# image-rendering

APISummary
## 简介

`image-rendering`

用于设置图像缩放算法。目前仅适用于 `<image>` 上展示的图片和 `background-image`

目前只应用于元件本身，不会在子元件上生效。

当前端指定的尺寸不是图像的原始尺寸时，图像将发生缩放。举个例子，如果有一张物理像素尺寸为 100×100 的图片，但实际宽高尺寸被设置为 200×200px（或 50×50px），然后，图片便会根据 image-rendering 指定的算法，缩小或放大到新尺寸。此属性对于未缩放的图像没有影响。

## 使用示例

**下面是一个示例: css-api**

**Entry:** `src/image-rendering`
**Bundle:** `dist/image-rendering.lynx.bundle`

```tsx
import { root } from "@lynx-js/react";
import "./index.scss";

const ImageRendering = () => {
  const url =
    "data:image/bmp;base64,Qk12BQAAAAAAADYAAAAoAAAAFQAAAOv///8BABgAAAAAAEAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////AAAAAAAA////////AAAA////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP///////////////////wAAAP///////wAAAP///////////////wAAAP///////////////////wAAAAAAAAD///8AAAAAAAAAAAD///8AAAD///8AAAAAAAAAAAD///////////8AAAD///8AAAAAAAAAAAD///8AAAAAAAAA////AAAAAAAAAAAA////AAAA////AAAAAAAA////////AAAA////AAAA////AAAAAAAAAAAA////AAAAAAAAAP///wAAAAAAAAAAAP///wAAAP///////wAAAAAAAP///////////wAAAP///wAAAAAAAAAAAP///wAAAAAAAAD///////////////////8AAAD///8AAAD///8AAAD///////////8AAAD///////////////////8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////AAAA////AAAA////AAAA////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAP///////////////////////////////wAAAP///wAAAP///////////////////////////////////////wAAAAAAAAD///8AAAD///////8AAAAAAAD///////8AAAAAAAAAAAAAAAAAAAAAAAD///8AAAAAAAD///8AAAAAAAAAAAAA////AAAAAAAA////////////////////AAAA////////AAAAAAAA////AAAAAAAA////AAAAAAAAAP///wAAAP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAP///////////////////wAAAP///////////wAAAAAAAAD///////8AAAAAAAD///////////////////////////////8AAAD///////8AAAAAAAD///8AAAAAAAAAAAAA////AAAAAAAAAAAA////////AAAA////////AAAAAAAAAAAA////////////AAAA////////////AAAAAAAAAP///////////////////////////////////////wAAAAAAAAAAAAAAAAAAAAAAAP///wAAAAAAAP///////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8AAAD///8AAAD///////////8AAAAAAAAAAAD///////8AAAD///8AAAAA////////////////////AAAA////////AAAAAAAA////////AAAA////////////////////////AAAAAAAAAP///wAAAAAAAAAAAP///wAAAP///////////wAAAP///wAAAP///wAAAP///////wAAAAAAAAAAAP///wAAAAD///8AAAAAAAAAAAD///8AAAD///8AAAAAAAD///8AAAAAAAAAAAAAAAAAAAD///8AAAD///8AAAD///8AAAAA////AAAAAAAAAAAA////AAAA////////AAAA////////////////AAAAAAAAAAAA////AAAA////////AAAAAP///////////////////wAAAP///wAAAP///wAAAAAAAAAAAAAAAP///////wAAAAAAAP///////////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8AAAAAAAAAAAD///////////////////8AAAD///////8AAAD///8A";

  const verticalStyle = {
    linearOrientation: "vertical" as const,
  };

  const pixelatedStyle = {
    imageRendering: "pixelated" as const,
  };

  const autoStyle = {
    imageRendering: "auto" as const,
  };

  const crispEdgesStyle = {
    imageRendering: "crisp-edges" as const,
  };

  return (
    <scroll-view>
      <view style={verticalStyle}>
        <view className="image size" style={pixelatedStyle}></view>
        <view className="image size" style={autoStyle}></view>
        <view className="image size" style={crispEdgesStyle}></view>
      </view>

      <view style={verticalStyle}>
        <image src={url} className="size" style={pixelatedStyle}></image>
        <image src={url} className="size" style={autoStyle}></image>
        <image src={url} className="size" style={crispEdgesStyle}></image>
      </view>
    </scroll-view>
  );
};

root.render(<ImageRendering />);

```

v0.11.0



## 语法

```css
image-rendering: auto;
image-rendering: crisp-edges;
image-rendering: pixelated;
```

### 取值

#### `auto`

默认值，平台层默认设置。一般实现为双线性插值

#### `crisp-edges`

必须使用可有效保留对比度和图像中的边缘的算法来对图像进行缩放，并且，该算法既不会平滑颜色，又不会在处理过程中为图像引入模糊。此属性值适用于像素艺术作品，例如一些网页游戏中的图像。
这个是为像素游戏设计的（参考 Pixel-art scaling algorithms），主流的浏览器并没有实现。
目前 lynx 暂未支持，效果与 auto 一致。

#### `pixelated`

放大和缩小图像时，使用最近邻居算法，因此，图像看着像是由大块像素组成的。

## 形式定义

| 初始值 | auto |
| 适用元素 | `image` 展示的图片, `background-image` |
| 是否支持继承 | no |
| 是否支持动画 | no |


## 形式语法

```
image-rendering = auto | crisp-edges | pixelated
```

## 与 Web 的区别

1. 仅对元件本身生效，不会在子元件生效。
2. 不支持全局属性值，例如 inherit, unset 等。

## 兼容性

**Compatibility Table**

**Query:** `css.properties.image-rendering`

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/208-image-rendering.json) · [MDN](https://developer.mozilla.org/zh-CN/docs/Web/CSS/image-rendering)

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| image-rendering | Partial (2.14) | Partial (3.4) | Partial (2.14) | Partial (2.14) | Partial (2.14) | Partial |

**`image-rendering`**

The image-rendering CSS property sets an image scaling algorithm. The property applies to an element itself.

- **Android — From 2.14:** Partial support; only <image> and  background-image supports, it only applies to an element itself.
- **HarmonyOS — From 3.4:** Partial support; only <image> and  background-image supports, it only applies to an element itself.
- **iOS — From 2.14:** Partial support; only <image> and  background-image supports, it only applies to an element itself.
- **macOS — From 2.14:** Partial support; only <image> and  background-image supports, it only applies to an element itself.
- **Windows — From 2.14:** Partial support; only <image> and  background-image supports, it only applies to an element itself.
- **Web — Supported (version unknown):** Partial support; it applies to an element itself, to any images set in its other properties, and to its descendants.

