ColorSamplers
A collections class allowing for array access into a document's ColorSamplers
Access this collection through the Document.colorSamplers property. For instance, the following adds a new colorSampler to the collection:
Copied to your clipboard1const app = require("photoshop").app;2app.activeDocument.colorSamplers.add({x: 20, y: 20});
A colorSampler can be access through the collection's [index]
property,
and then queried for its properties.
For example, the following gets the first colorSampler in the collection, and then
unpacks its color
and position
properties via a destructuring assignment to get
the sampled color as a SolidColor object and its current position as an {x, y}
object:
Copied to your clipboard1const cs = app.activeDocument.colorSamplers[0];2const { color, position } = cs; // destructuring assignment3console.log(color.rgb); // returns a SolidColor object:4 // {red: 0, green: 255, blue: 0, model: ColorModel.RGB}5console.log(position); // returns an object: {x: 20, y: 20}6
To empty the colorSamplers collection, use the removeAll()
method.
Copied to your clipboard1app.activeDocument.colorSamplers.removeAll();2app.activeDocument.colorSamplers.length; // returns 0
Properties
名称 | 类型 | 访问 | 最低版本 | 描述 |
---|---|---|---|---|
length | number | R | 24.0 | Number of ColorSampler elements in this collection. ```javascript // A new document starts with no colorSamplers app.activeDocument.colorSamplers.length; // returns 0 ``` |
parent | Document | R | 24.0 | The owner Document of this ColorSamplers collection. |
Methods
add
24.0Adds a ColorSampler to the collection at the given {x, y}
coordinates in pixels.
Copied to your clipboard1app.activeDocument.colorSamplers.add({x: 20, y: 20});2app.activeDocument.colorSamplers.length; // returns 1
Parameters
名称 | 类型 |
---|---|
position | object |
position.x | number |
position.y | number |
removeAll
24.0void
Removes all ColorSampler instances from this collection.
Copied to your clipboard1app.activeDocument.colorSamplers.removeAll();2app.activeDocument.colorSamplers.length; // returns 0