大网数据广告活动
Web 标准与前端开发

ImageDecoder: ImageDecoder() constructor

· 52CE 我爱测

The **`ImageDecoder()`** constructor creates a new ImageDecoder object which unpacks and decodes image data.

WebCodecs APIwindow_and_dedicated

The ImageDecoder() constructor creates a new ImageDecoder object which unpacks and decodes image data.

Syntax

new ImageDecoder(init)

Parameters

  • init
    • : An object containing the following members:
      • type
        • : A string containing the MIME type of the image file to be decoded.
      • data
        • : An ArrayBuffer, a TypedArray, a DataView, or a ReadableStream of bytes representing an encoded image type as described by type.
      • colorSpaceConversion
        • : Specifies whether the image should be decoded using color space conversion. If not provided set as "default". The value "default" indicates that implementation-specific behavior is used:
          • "none"
          • "default"
      • desiredWidth
        • : An integer indicating the desired width for the decoded output. Has no effect unless the image codec supports variable resolution decoding.
      • desiredHeight
        • : An integer indicating the desired height for the decoded output. Has no effect unless the image codec supports variable resolution decoding.
      • preferAnimation
        • : A Boolean indicating whether the initial track selection should prefer an animated track.
      • transfer
        • : An array of ArrayBuffers that ImageDecoder will detach and take ownership of. If the array contains the ArrayBuffer backing data, ImageDecoder will use that buffer directly instead of copying from it.

Examples

The following example creates a new ImageDecoder with the required options.

let init = {
  type: "image/png",
  data: imageByteStream,
};

let imageDecoder = new ImageDecoder(init);

Specifications

Browser compatibility

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。