• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

color sampler in the foreground

Advocate ,
Oct 14, 2017 Oct 14, 2017

Copy link to clipboard

Copied

I would like the color selected by color sample

be put in the foreground window.

444.jpg

TOPICS
Actions and scripting

Views

846

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 14, 2017 Oct 14, 2017

// 2017, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

app.foregroundColor = myDocument.colorSamplers[0].color

};

Votes

Translate

Translate
Adobe
Community Expert ,
Oct 14, 2017 Oct 14, 2017

Copy link to clipboard

Copied

// 2017, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

app.foregroundColor = myDocument.colorSamplers[0].color

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 14, 2017 Oct 14, 2017

Copy link to clipboard

Copied

It works perfectly

because you wrote it use it at your own risk?

sorry if you take advantage of your help

and if I wanted to pick the color of a selection

be put in the foreground window.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 14, 2017 Oct 14, 2017

Copy link to clipboard

Copied

because you wrote it use it at your own risk?

I just like to make sure that I make no guarantees about Scripts I post.

and if I wanted to pick the color of a selection

be put in the foreground window.

What do you mean exactly? A Selection may cover any number of pixels of different colors, do you mean the average?

Maybe posting a screenshot or mock-up might help me understand what you are trying to achieve.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 14, 2017 Oct 14, 2017

Copy link to clipboard

Copied

A selection can cover any number of pixels of different colors, do you mean the average?

I meant the average.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 14, 2017 Oct 14, 2017

Copy link to clipboard

Copied

You have to test whether this gives you the intended results:

// set foregtound color to selection average;

// 2017, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

if (myDocument.mode == DocumentMode.RGB) {

var theR = histogramMean (myDocument.channels[0].histogram);

var theG = histogramMean (myDocument.channels[1].histogram);

var theB = histogramMean (myDocument.channels[2].histogram);

// make forground color;

var theColor = new SolidColor();

theColor.rgb.red = theR;

theColor.rgb.green = theG;

theColor.rgb.blue = theB;

app.foregroundColor = theColor;

};

};

//////

function histogramMean (histo) {

var mean = 0;

var total = 0;

for (var n = 0; n < histo.length; n++) {

total = total + histo;

};

for (var m = 0; m < histo.length; m++) {

var thisValue = histo;

mean = mean + (m * thisValue / total);

};

return mean

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 14, 2017 Oct 14, 2017

Copy link to clipboard

Copied

Perfect

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 14, 2017 Oct 14, 2017

Copy link to clipboard

Copied

The code would only work for RGB images, if you need to precess others (CMYK, Grayscale …) you need to adapt it accordingly.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 14, 2017 Oct 14, 2017

Copy link to clipboard

Copied

LATEST

thanks for your time.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines