ImageData: colorSpace プロパティ
読み取り専用プロパティ ImageData.colorSpace
は、画像データの色空間を表す文字列です。
色空間は、ImageData()
コンストラクターまたは createImageData()
メソッドを用いて、ImageData
の初期化時に設定できます。
値
このプロパティは以下の値を取りえます。
- sRGB 色空間を表す
"srgb"
- display-p3 色空間を表す
"display-p3"
例
キャンバスの画像データの色空間の取得
getImageData()
では、色空間を明示的に要求できます。この色空間がキャンバスの初期化時の色空間と異なる場合は、変換が行われます。ImageData
オブジェクトの色空間を知るには、colorSpace
プロパティを用います。
js
const context = canvas.getContext("2d", { colorSpace: "display-p3" });
context.fillStyle = "color(display-p3 0.5 0 0)";
context.fillRect(0, 0, 10, 10);
const p3ImageData = context.getImageData(0, 0, 1, 1);
console.log(p3ImageData.colorSpace); // "display-p3"
const srgbImageData = context.getImageData(0, 0, 1, 1, { colorSpace: "srgb" });
console.log(srgbImageData.colorSpace); // "srgb"
仕様書
Specification |
---|
HTML # dom-imagedata-colorspace |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
colorSpace |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
The compatibility table on 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.