Getting Colour Information for a pixel

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

lumleyfamily

Getting Colour Information for a pixel

Post by lumleyfamily »

Does PS Scripiting have a function to retrieve colour information for a specific pixel at reference (x,y)? if so, where would I find a list of these types of functions?

Regards,

Bob
MickM

Getting Colour Information for a pixel

Post by MickM »

xbytor posted this recently on the Adobe forum. I think this code was originally written by fazstp.

Code: Select allfunction GetPixel( varX, varY ) {
   // make new 1 pixel selection
   activeDocument.selection.select( [[varX, varY], [varX + 1, varY], [varX + 1,
varY + 1], [varX, varY + 1]] );

   // init colour
   var pColour = new SolidColor();

   // get red histogram
   var pChannel = activeDocument.channels["Red"].histogram;

   // check 0 to 255
   for ( i = 0; i <= 255; i++ ) {
     if ( pChannel ) {
       pColour.rgb.red = i;
       break;
     }
   }

   // get green histogram
   pChannel = activeDocument.channels["Green"].histogram;

   // check 0 to 255
   for ( i = 0; i <= 255; i++ ) {
     if ( pChannel ) {
       pColour.rgb.green = i;
       break;
     }
   }

   // get blue histogram
   pChannel = activeDocument.channels["Blue"].histogram;

   // check 0 to 255
   for ( i = 0; i <= 255; i++ ) {
     if ( pChannel ) {
       pColour.rgb.blue = i;
       break;
     }
   }

   return pColour;
}
lumleyfamily

Getting Colour Information for a pixel

Post by lumleyfamily »

Thanks Mick. I'll see how it runs tomorrow.

Regards,

Bob
lumleyfamily

Getting Colour Information for a pixel

Post by lumleyfamily »

Yep - It all worked well. Thanks Mick.
MickM

Getting Colour Information for a pixel

Post by MickM »

Don't thank me Bob. I just posted it because I had seen it a few days earlier.