简体   繁体   中英

Photoshop select script

I spent all day attempting to write a javascript which selects all white pixels in a bitmap

I used a loop within a loop to iterate through all of the pixels one by one (the outer loop went through the vertical lines and inner loop went though the horizontal ones)

and used coloursampler to detect if the pixels RGB values were close enough to 255 or not.

anyway this code took a very very long time to complete i literally saw the colour sample cursor move over every single pixel one at a time.

I the found out that I could record an action which selects all colours within a range from the whole image and call it from my script, and this worked instantly.

I am not surprised that my way was slow. but that raises the question

How come Photoshop is able to scan a whole document for pixels which meet certain criteria using select>range and tools such as the magic wand and quick select yet my code runs so slow Surely photoshop must need to scan each individual pixel so achieve such effects.

For elements of Photoshop which are not directly supported by the Javascript API (color range selection is one of them) I suggest you look into using the Adobe Scripting Listener plugin, and utilize the script listener's output for the core of your script.

I have written a tutorial on how to utilize the script listener for Color selection here . The tutorials use Python, but the overall concepts are exactly the same- the scripting listener even puts out a pure JS file for you!

This will be much faster than iterating over pixels, as it gives you access to the same fast tools and actions that are core parts of the Photoshop Application.

Hope that helps out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM