WebGLRenderingContext.pixelStorei()
===================================

**`WebGLRenderingContext.pixelStorei()`** 是 WebGL API 中用于图像预处理的函数。

语法
--
```

void gl.pixelStorei(pname, param);
```

### 参数

pname

`Glenum` (en-US) 类型，表示处理的方式。关于该参数可选值，请见下面表格。

param

`GLint` (en-US) 类型，表示 pname 处理方式的参数。关于该参数可选值，请见下面表格。

### 返回值

None.

像素存储参数
------

| 模式名称 (`pname`) | 描述 | 类型 | 默认值 | param 的可选值 | Specified in |
| --- | --- | --- | --- | --- | --- |
| `gl.PACK_ALIGNMENT` | Packing of pixel data into memory | `GLint` (en-US) | 4 | 1, 2, 4, 8 | OpenGL ES 2.0 |
| `gl.UNPACK_ALIGNMENT` | Unpacking of pixel data from memory. | `GLint` (en-US) | 4 | 1, 2, 4, 8 | OpenGL ES 2.0 |
| `gl.UNPACK_FLIP_Y_WEBGL` | 如果为 true，则把图片上下对称翻转坐标轴 (图片本身不变)。 | `GLboolean` (en-US) | false | true, false | WebGL |
| `gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL` | Multiplies the alpha channel into the other color channels | `GLboolean` (en-US) | false | true, false | WebGL |
| `gl.UNPACK_COLORSPACE_CONVERSION_WEBGL` | Default color space conversion or no color space conversion. | `GLenum` (en-US) | `gl.BROWSER_DEFAULT_WEBGL` | `gl.BROWSER_DEFAULT_WEBGL`, `gl.NONE` | WebGL |

When using a WebGL 2 context, the following values are available additionally:

| Constant | Description | Type | Default value | Allowed values (for `param`) | Specified in |
| --- | --- | --- | --- | --- | --- |
| `gl.PACK_ROW_LENGTH` | Number of pixels in a row. | `GLint` (en-US) | 0 | 0 to `Infinity` | OpenGL ES 3.0 |
| `gl.PACK_SKIP_PIXELS` | Number of pixel locations skipped before the first pixel is written into memory. | `GLint` (en-US) | 0 | 0 to `Infinity` | OpenGL ES 3.0 |
| `gl.PACK_SKIP_ROWS` | Number of rows of pixel locations skipped before the first pixel is written into memory | `GLint` (en-US) | 0 | 0 to `Infinity` | OpenGL ES 3.0 |
| `gl.UNPACK_ROW_LENGTH` | Number of pixels in a row. | `GLint` (en-US) | 0 | 0 to `Infinity` | OpenGL ES 3.0 |
| `gl.UNPACK_IMAGE_HEIGHT` | Image height used for reading pixel data from memory | `GLint` (en-US) | 0 | 0 to `Infinity` | OpenGL ES 3.0 |
| `gl.UNPACK_SKIP_PIXELS` | Number of pixel images skipped before the first pixel is read from memory | `GLint` (en-US) | 0 | 0 to `Infinity` | OpenGL ES 3.0 |
| `gl.UNPACK_SKIP_ROWS` | Number of rows of pixel locations skipped before the first pixel is read from memory | `GLint` (en-US) | 0 | 0 to `Infinity` | OpenGL ES 3.0 |
| `gl.UNPACK_SKIP_IMAGES` | Number of pixel images skipped before the first pixel is read from memory | `GLint` (en-US) | 0 | 0 to `Infinity` | OpenGL ES 3.0 |

Examples
--------

Setting the pixel storage mode affects the `WebGLRenderingContext.readPixels()` operations, as well as unpacking of textures with the `WebGLRenderingContext.texImage2D()` and `WebGLRenderingContext.texSubImage2D()` (en-US) methods.


```js
var tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE\_2D, tex);
gl.pixelStorei(gl.PACK\_ALIGNMENT, 4);
```


To check the values for packing and unpacking of pixel data, you can query the same pixel storage parameters with `WebGLRenderingContext.getParameter()`.


```js
gl.getParameter(gl.PACK\_ALIGNMENT);
gl.getParameter(gl.UNPACK\_ALIGNMENT);
```

Specifications
--------------

| Specification |
| --- |
| WebGL Specification # 5.14.3 |
| WebGL Specification # PIXEL\_STORAGE\_PARAMETERS |
| WebGL 2.0 Specification # 3.7.2 |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `WebGLRenderingContext.readPixels()`
* `WebGLRenderingContext.texImage2D()`
* `WebGLRenderingContext.texSubImage2D()` (en-US)