I am trying to automate filling a channel with a specified color. Can anyone tell me why the following code will fill the channel, but with the wrong color (149,149,149 instead of 128,128,128)? I am using Photoshop CS3. Thank you
Code: Select all#target photoshop
app.bringToFront();
app.activeDocument.selection.selectAll();
// Make "Alpha 1" the active channel
app.activeDocument.activeChannels = [app.activeDocument.channels.getByName("Alpha 1")];
// Create a color to fill the "Alpha 1" channel with.
var fillColor = new SolidColor();
fillColor.rgb.red = 128;
fillColor.rgb.green = 128;
fillColor.rgb.blue = 128;
app.activeDocument.selection.fill(fillColor);
Filling a channel results in incorrect color
Filling a channel results in incorrect color
There are two things going on. One is a single channel can not contain a RGB color. For channels you should use fillColor.gray.gray = someValue; You can use an RGB color but it will be converted( see below )
The other thing is unless the document is in Grayscale mode that gray color has to be converted into whatever the document's color mode is and that conversion is made using the defalut gray profile in the apps color settings. For example if I run your code with the defalut gray profile set to 'dot gain 20%' I get the same results( 149, 149, 149 ). But if I change it to 'Gray Gamma 2.2' I get 129, 129, 129 which is closer to what you seem to expect.
The other thing is unless the document is in Grayscale mode that gray color has to be converted into whatever the document's color mode is and that conversion is made using the defalut gray profile in the apps color settings. For example if I run your code with the defalut gray profile set to 'dot gain 20%' I get the same results( 149, 149, 149 ). But if I change it to 'Gray Gamma 2.2' I get 129, 129, 129 which is closer to what you seem to expect.