lph*_*phd 5 javascript cs4 photoshop-script
我想弄清楚如何获得一个定义的像素的颜色。
在我的想象中,它应该是这样的:
color = get.color.Pixel(x,y);
Run Code Online (Sandbox Code Playgroud)
也许有人可以帮助我处理这段代码?
Photoshop 的 JavaScript API 没有提供您在问题中想象的机制。
您需要使用该Document.colorSamplers.add([x, y])方法,然后通过其属性读取每个组件的颜色值:
以下要点示出了如何获得任一rgb或cmyk对于给定的值x,y的坐标:
#target photoshop
// Define the x and y coordinates for the pixel to sample.
var x = 1;
var y = 1;
// Add a Color Sampler at a given x and y coordinate in the image.
var pointSample = app.activeDocument.colorSamplers.add([(x - 1),(y - 1)]);
// Obtain array of RGB values.
var rgb = [
pointSample.color.rgb.red,
pointSample.color.rgb.green,
pointSample.color.rgb.blue
];
// Obtain array of rounded CMYK values.
var cmyk = [
Math.round(pointSample.color.cmyk.cyan),
Math.round(pointSample.color.cmyk.magenta),
Math.round(pointSample.color.cmyk.yellow),
Math.round(pointSample.color.cmyk.black)
];
// Remove the Color Sampler.
pointSample.remove();
// Display the complete RGB values and each component color.
alert('RGB: ' + rgb)
alert('red: ' + rgb[0])
alert('green: ' + rgb[1])
alert('blue: ' + rgb[2])
// Display the complete CMYK values and each component color.
alert('CMYK: ' + cmyk)
alert('cyan: ' + cmyk[0])
alert('magenta: ' + cmyk[1])
alert('yellow: ' + cmyk[2])
alert('black: ' + cmyk[3])
Run Code Online (Sandbox Code Playgroud)