Monday 28 January 2013

More About sampleImage()


More About sampleImage()

You can sample the color and alpha data of a
rectangular area of a layer using the layer method
sampleImage(). You supply up to four
parameters to sampleImage() and it returns
color and alpha data as a four-element array ([red,
green, blue, alpha]), where the values have been
normalized so that they fall between 0.0 and 1.0.
The four parameters are
. Sample point
. Sample radius
. Post-effect flag
. Sample time
The sample point is given in layer space
coordinates, where [0, 0] represents the center
of the layer’s top left pixel. The sample radius is
a two-element array ([x radius, y radius]) that
specifies the horizontal and vertical distance from
the sample point to the edges of the rectangular
area being sampled. To sample a single pixel, you
would set this value to [0.5, 0.5] (half a pixel in
each direction from the center of the pixel at the
sample point). The post-effect flag is optional (its
default value is true if you omit it) and specifies
whether you want the sample to be taken after
masks and effects are applied to the layer (true) or
before (false). The sample time parameter specifies
the time at which the sample is to be taken. This
parameter is also optional (the default value is the
current composition time), but if you include it, you
must also include the post-effect flag parameter.
As an example, here’s how you could sample the
red value of the pixel at a layer’s center, after any
effects and masks have been applied, at a time one
second prior to the current composition time:
mySample = sampleImage([width/
➥height]/2, [0.5,0.5], true,
➥time – 1);
myRedSample = mySample[0];

No comments:

Post a Comment