I am trying to figure out how to get the color of one defined Pixel.
In my imagination its shoud look like:
color = get.color.Pixel(x,y);
Maybe someone can help me with this piece of code?
I am trying to figure out how to get the color of one defined Pixel.
In my imagination its shoud look like:
color = get.color.Pixel(x,y);
Maybe someone can help me with this piece of code?
2
Answers
Photoshop’s JavaScript API doesn’t provide a mechanism like you imagine in your question.
You’ll need to utilize the
Document.colorSamplers.add([x, y])
method, then read each component color value via its properties:The following gist shows how to obtain either
rgb
orcmyk
values for a givenx,y
coordinate:Here’s a simple script using a
ColorSampler
. It’s set up to return RGB values.This gives me pixel values at about 100 pixels per second on my machine.
I found this and cleaned up the script a bit. Basically, the idea is to:
This gives me pixel values at about 72,000 pixels per second, not including the overhead of writing the raw data to disk and reading it back in. It has the added benefit that you can set pixel values, too.