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.
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!
...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")
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); }
}
Copy link to clipboard
Copied
r-bin
Very good!
Thank you!