maybe the @r-bin will help.
By @jazz-y
Привет, Дима. Слушай, мне некогда корячиться с переводчиком. Расталкуй товарищу как работает эта функция https://community.adobe.com/t5/photoshop-ecosystem-discussions/get-color-from-selected-area/m-p/12113603#M553549
Там нужно заменить x+1 и y+1 на x+51 и y+51, ну или по желанию.
Спасибо! Я уже накидал свой вариант, но, конечно, в более сокращенном виде 🙂
This code is only suitable for RGB:
const AVERAGE_AREA = 51;
var startRulerUnits = app.preferences.rulerUnits,
startTypeUnits = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.PIXELS
app.preferences.typeUnits = TypeUnits.PIXELS
var doc = activeDocument,
colorSampler = activeDocument.colorSamplers[0],
x = colorSampler.position[0].value,
y = colorSampler.position[1].value;
var selRegion = [
[x - AVERAGE_AREA / 2, y - AVERAGE_AREA / 2],
[x + AVERAGE_AREA / 2, y - AVERAGE_AREA / 2],
[x + AVERAGE_AREA / 2, y + AVERAGE_AREA / 2],
[x - AVERAGE_AREA / 2, y + AVERAGE_AREA / 2]
]
doc.selection.select(selRegion)
var mean= [],
color = new SolidColor;
for (var i = 0; i < doc.channels.length; i++) {
var n = p = 0,
cur = doc.channels[i].histogram;
for (var x = 0; x < cur.length; x++) {
n += cur[x]
p += cur[x] * x
}
mean.push(p / n)
}
doc.selection.deselect()
with (color.rgb) { red = mean[0]; green = mean[1]; blue = mean[2]; };
var readColorHue = Math.round(color.hsb.hue)
var readColorSaturation = Math.round(color.hsb.saturation)
var readColorBrightness = Math.round(color.hsb.brightness)
alert('H ' + readColorHue + ' S ' + readColorSaturation + ' B ' + readColorBrightness)
app.preferences.rulerUnits = startRulerUnits
app.preferences.typeUnits = startTypeUnits
@r-bin proposed a similar solution to this problem, but it is more complete and faster. At the link above you will find a function that changes app.foregroundColor to the color at the given point. You can get the coordinates of this point from the .position property of the colorSampler. After that, you need to create a selection by sequentially describing the coordinates of the selection points (note that @r-bin shifts the coordinates to the right down from the desired point by 1 pixel, you need to rewrite the code so that the point you need is in the center of the selection). Further, everything is simple - after executing the function, you just need to read the color value of app.foregroundColor