3 Replies Latest reply on Nov 13, 2014 12:00 PM by xbytor2

    how to get any location of image color data?

    roychen Level 1

      // =======================================================

      var idsetd = charIDToTypeID( "setd" );

          var desc1197 = new ActionDescriptor();

          var idnull = charIDToTypeID( "null" );

              var ref958 = new ActionReference();

              var idChnl = charIDToTypeID( "Chnl" );

              var idfsel = charIDToTypeID( "fsel" );

              ref958.putProperty( idChnl, idfsel );

          desc1197.putReference( idnull, ref958 );

          var idT = charIDToTypeID( "T   " );

              var desc1198 = new ActionDescriptor();

              var idTop = charIDToTypeID( "Top " );

              var idPxl = charIDToTypeID( "#Pxl" );

              desc1198.putUnitDouble( idTop, idPxl, 1096.000000 );//i input Coordinate location data

              var idLeft = charIDToTypeID( "Left" );

              var idPxl = charIDToTypeID( "#Pxl" );

              desc1198.putUnitDouble( idLeft, idPxl, 2188.000000 );//i input Coordinate location data

              var idBtom = charIDToTypeID( "Btom" );

              var idPxl = charIDToTypeID( "#Pxl" );

              desc1198.putUnitDouble( idBtom, idPxl, 1097.000000 );//i input Coordinate location data

              var idRght = charIDToTypeID( "Rght" );

              var idPxl = charIDToTypeID( "#Pxl" );

              desc1198.putUnitDouble( idRght, idPxl, 2189.000000 );//i input Coordinate location data

          var idRctn = charIDToTypeID( "Rctn" );

          desc1197.putObject( idT, idRctn, desc1198 );

      executeAction( idsetd, desc1197, DialogModes.NO );

       

       

      // =======================================================

      var idslct = charIDToTypeID( "slct" );

          var desc1199 = new ActionDescriptor();

          var idnull = charIDToTypeID( "null" );

              var ref959 = new ActionReference();

              var ideyedropperTool = stringIDToTypeID( "eyedropperTool" );

              ref959.putClass( ideyedropperTool );

          desc1199.putReference( idnull, ref959 );

          var iddontRecord = stringIDToTypeID( "dontRecord" );

          desc1199.putBoolean( iddontRecord, true );

          var idforceNotify = stringIDToTypeID( "forceNotify" );

          desc1199.putBoolean( idforceNotify, true );

      executeAction( idslct, desc1199, DialogModes.NO );

       

       

      // =======================================================

      var idsetd = charIDToTypeID( "setd" );

          var desc1200 = new ActionDescriptor();

          var idnull = charIDToTypeID( "null" );

              var ref960 = new ActionReference();

              var idClr = charIDToTypeID( "Clr " );

              var idFrgC = charIDToTypeID( "FrgC" );

              ref960.putProperty( idClr, idFrgC );

          desc1200.putReference( idnull, ref960 );

          var idT = charIDToTypeID( "T   " );

              var desc1201 = new ActionDescriptor();

              var idCyn = charIDToTypeID( "Cyn " );

              desc1201.putDouble( idCyn, 55.290000 );//i want to get clor data, c=?

              var idMgnt = charIDToTypeID( "Mgnt" );

              desc1201.putDouble( idMgnt, 54.510000 );//i want to get clor data, m=?

              var idYlw = charIDToTypeID( "Ylw " );

              desc1201.putDouble( idYlw, 69.410000 );//i want to get clor data, y=?

              var idBlck = charIDToTypeID( "Blck" );

              desc1201.putDouble( idBlck, 43.140000 );////i want to get clor data, k=?

          var idCMYC = charIDToTypeID( "CMYC" );

          desc1200.putObject( idT, idCMYC, desc1201 );

          var idSrce = charIDToTypeID( "Srce" );

          desc1200.putString( idSrce, """eyeDropperSample""" );

      executeAction( idsetd, desc1200, DialogModes.NO );

       

       

       

       

      i draw Rectangle (1px x 1px)...i want to get any location of image color data, Can be achieved by javascript? pls help meUntitled-2.jpg

        • 1. Re: how to get any location of image color data?
          JJMack Most Valuable Participant

          roychen wrote:

            

          i draw Rectangle (1px x 1px)...i want to get any location of image color data, Can be achieved by javascript? pls help me

          If the rectangle you draw out is a selection the selection has bounds. So you can use the bounds to get the location and size. You can also do a copy paste in a new layer.  Use the histogram of the new layer to get the color information.  I have never played with programming the histogram information but remember seeing a sample in Photoshop Scripting javascript reference.  If its one pixel it should be qiick.

          • 2. Re: Re: how to get any location of image color data?
            Chuck Uebele Adobe Community Professional & MVP

            This will only work if you make a selection:

             

            #target photoshop
            var doc = activeDocument;
            doc.colorSamplers.removeAll();
            var pt = [doc.selection.bounds[0],doc.selection.bounds[1]];
            var sampleColor = doc.colorSamplers.add(pt);
            alert('Cyan: ' + sampleColor.color.cmyk.cyan +'\n' +'Magenta: ' + sampleColor.color.cmyk.magenta +'\n' +'Yellow: ' + sampleColor.color.cmyk.yellow +'\n' +'Black: ' + sampleColor.color.cmyk.black);
            
            • 3. Re: Re: how to get any location of image color data?
              xbytor2 Level 4

              For a single pixel in CS3+, try this:

               

              function getColorAt(doc, x, y) {
                var sample = doc.colorSamplers.add([UnitValue(x, "px"), UnitValue(y, "px")]);
                var clr = undefined;
                try { clr = sample.color; } catch (e) {}
                sample.remove()
                return clr;
              }
              

               

               

              If it's more than a pixel, JJMack's suggestion should work well. Just remember that there are only 256 slots in the histogram which means it's only depth of 8 bits.

               

              -X