• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Position x and y of each non-transparent pixel of the active layer

Explorer ,
Nov 02, 2018 Nov 02, 2018

Copy link to clipboard

Copied

Hi

I need to know the position x and y of each non-transparent pixel of the active layer.

Example:

Image applied at 200%. Size: W 525px, H 270px, 72dpi.

Each square represents one pixel.

ExampleA.png

return [x,y]; //~ Left, Top

//~ That is

myArrayPositions.push([x,y]);

//~ myArrayPositions.push([2,0]);

//~ myArrayPositions.push([5,1]);

//~ myArrayPositions.push([11,2]);

//~ myArrayPositions.push([2,4]);

//~ myArrayPositions.push([3,4]);

But I have difficulties.

To this day, everything I've tried has not worked or is too slow to become feasible.

Working with Windows / Photoshop CS6 / VBS / JSX

Thanks!

TOPICS
Actions and scripting

Views

325

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , Nov 02, 2018 Nov 02, 2018

app.preferences.rulerUnits = Units.PIXELS;

var doc0 = app.activeDocument;

var w = doc0.width.value;

var h = doc0.height.value;

app.activeDocument.quickMaskMode = false;

selection_from_layer();

app.activeDocument.quickMaskMode = true;

var d = new ActionDescriptor();

d.putClass(stringIDToTypeID("new"), stringIDToTypeID("document"));

var r = new ActionReference();

r.putEnumerated(stringIDToTypeID("channel"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

d.putReference(stringIDToTypeID("using")

...

Votes

Translate

Translate
Adobe
People's Champ ,
Nov 02, 2018 Nov 02, 2018

Copy link to clipboard

Copied

app.preferences.rulerUnits = Units.PIXELS;

var doc0 = app.activeDocument;

var w = doc0.width.value;

var h = doc0.height.value;

app.activeDocument.quickMaskMode = false;

selection_from_layer();

app.activeDocument.quickMaskMode = true;

var d = new ActionDescriptor();

d.putClass(stringIDToTypeID("new"), stringIDToTypeID("document"));

var r = new ActionReference();

r.putEnumerated(stringIDToTypeID("channel"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

d.putReference(stringIDToTypeID("using"), r);

executeAction(stringIDToTypeID("make"), d, DialogModes.NO);

var file = new File(Folder.temp.fsName + "\\" + "pixels.raw");

var d = new ActionDescriptor();

var d1 = new ActionDescriptor();

d1.putString(stringIDToTypeID("fileCreator"), "8BIM");

d.putObject(stringIDToTypeID("as"), stringIDToTypeID("rawFormat"), d1);

d.putPath(stringIDToTypeID("in"), file);

d.putBoolean(stringIDToTypeID("copy"), true);

executeAction(stringIDToTypeID("save"), d, DialogModes.NO);

app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

app.activeDocument = doc0;

doc0.quickMaskMode = false;

doc0.selection.deselect();

file.open("r");

file.encoding = "BINARY";

var data = file.read();

file.close();

file.remove();

var result = new Array();

for (x = 0; x < w; x++)

    for (y = 0; y < h; y++)

        if (data.charCodeAt(x+w*y) != 255) result.push([x,y]);

alert(result.toSource())

function selection_from_layer()  

    {  

    try  

        {  

        var r = new ActionReference();  

        r.putProperty(stringIDToTypeID("channel"), stringIDToTypeID("selection"));  

        var d = new ActionDescriptor();  

        d.putReference(stringIDToTypeID("null"), r);  

        var r = new ActionReference();  

        r.putEnumerated(stringIDToTypeID("channel"), stringIDToTypeID("channel"), stringIDToTypeID("transparencyEnum"));  

        d.putReference(stringIDToTypeID("to"), r);  

        executeAction(stringIDToTypeID("set"), d, DialogModes.NO);  

        }  

    catch (e) { throw(e); }  

    }   

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 02, 2018 Nov 02, 2018

Copy link to clipboard

Copied

LATEST

r-bin

Very good!

Thank you!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines