Skip to main content
yangt11557531
Participant
July 25, 2018
Frage

Get index of each pixel?

  • July 25, 2018
  • 2 Antworten
  • 2956 Ansichten

I'm new to Photoshop scripting (am using JavaScript) and was wondering how to get access to each pixel. I have tried doing things like:

var docRef = app.activeDocument

pixelRef = docRef.pixel[0]

Then I could (hopefully) access things like the pixel's color. Please help me!

Dieses Thema wurde für Antworten geschlossen.

2 Antworten

JJMack
Community Expert
Community Expert
July 25, 2018

Layers can be any size.  Only a Layers pixel over the document canvas are visible if the layer visibility is on.  Any of the visible pixels can be address with a color sampler and you can access its color.  You can set up to 10 Color samplers.  I do not know how you can address a layer pixels that are clipped by the Document canvas size.  Color samplers are relaive to canvas size and seem to be confind to be within the canvas Area. If you add or remove camvas a color sampler position remains relative to canvas and is adjusted by Photoshop during the canvas size change. Which may mean removing samplers that would no longer be within canvas the document canvas. The Sampler Color is for the Image composit pixel so set layer visibility to what you want to sample.

JJMack
Silly-V
Legend
July 25, 2018

Wow when did they increase that to 10, I always thought it was 4!

Oh duh the answer is in the code snippet above! Wow!~

s = (parseFloat(version) > 13.1 ? 10 : 4)

Kukurykus
Legend
July 25, 2018
Kukurykus
Legend
July 25, 2018

function cS(v1, v2) {

     with(preferences) {

          s = (parseFloat(version) > 14.1 ? 10 : 4)

          if ((len = (cs = (aD = activeDocument)

          .colorSamplers).length) < s) {

               pixels = Units.PIXELS; function rU(v) {

                    if (v) cU = rulerUnits, rulerUnits = pixels

               }

               if (u = rulerUnits != pixels) rU(u)

               cs.add([v1,v2]); if (u) rulerUnits = cU

               hexColor = cs[len].color.rgb.hexValue

               return cs[len].remove(), hexColor

          }

          else aD.colorSamplers.removeAll(), cS(v1, v2)

     }

}

cS(225, 275)