WebGLRenderingContext.pixelStorei() - Web API 接口参考 编辑
WebGLRenderingContext.pixelStorei()
是 WebGL API 中用于图像预处理的函数。
语法
void gl.pixelStorei(pname, param);
参数
返回值
None.
像素存储参数
模式名称 (pname ) | 描述 | 类型 | 默认值 | param 的可选值 | Specified in |
---|---|---|---|---|---|
gl.PACK_ALIGNMENT | Packing of pixel data into memory | GLint | 4 | 1, 2, 4, 8 | OpenGL ES 2.0 |
gl.UNPACK_ALIGNMENT | Unpacking of pixel data from memory. | GLint | 4 | 1, 2, 4, 8 | OpenGL ES 2.0 |
gl.UNPACK_FLIP_Y_WEBGL | 如果为true,则把图片上下对称翻转坐标轴(图片本身不变)。 | GLboolean | false | true, false | WebGL |
gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL | Multiplies the alpha channel into the other color channels | GLboolean | false | true, false | WebGL |
gl.UNPACK_COLORSPACE_CONVERSION_WEBGL | Default color space conversion or no color space conversion. | GLenum | 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 | 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 | 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 | 0 | 0 to Infinity | OpenGL ES 3.0 |
gl.UNPACK_ROW_LENGTH | Number of pixels in a row. | GLint | 0 | 0 to Infinity | OpenGL ES 3.0 |
gl.UNPACK_IMAGE_HEIGHT | Image height used for reading pixel data from memory | GLint | 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 | 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 | 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 | 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()
methods.
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()
.
gl.getParameter(gl.PACK_ALIGNMENT);
gl.getParameter(gl.UNPACK_ALIGNMENT);
Specifications
Specification | Status | Comment |
---|---|---|
WebGL 1.0 pixelStorei | Recommendation | Initial definition for WebGL. |
WebGL 1.0 Pixel Storage Parameters | Recommendation | Additional pixel storage parameters that aren't specified in OpenGL. |
OpenGL ES 2.0 glPixelStorei | Standard | Man page of the OpenGL ES 2.0 API. |
WebGL 2.0 pixelStorei | Editor's Draft | Updated definition for WebGL 2. |
OpenGL ES 3.0 glPixelStorei | Standard | Man page of the OpenGL ES 3.0 API. |
Browser compatibility
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
No compatibility data found. Please contribute data for "api/WebGLRenderingContext" (depth: WebGLRenderingContext.pixelStorei) to the MDN compatibility data repository.
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论