您可以使用以下自定义makeCircleSelection
函数.如您所见,其签名有三个参数,即x
、y
和radius
.
/**
* Make a circular selection.
* @param {Number} x The center of the circular selection on the x-axis.
* @param {Number} y The center of the circular selection on the y-axis.
* @param {Number} radius The radius of the circular selection.
* @returns {Object} A reference to the newly created circular selection.
*/
function makeCircleSelection(x, y, radius) {
var d1 = new ActionDescriptor();
var d2 = new ActionDescriptor();
var ref = new ActionReference();
d1.putUnitDouble(charIDToTypeID('Top '), charIDToTypeID('#Pxl'), y - radius);
d1.putUnitDouble(charIDToTypeID('Left'), charIDToTypeID('#Pxl'), x - radius);
d1.putUnitDouble(charIDToTypeID('Btom'), charIDToTypeID('#Pxl'), y + radius);
d1.putUnitDouble(charIDToTypeID('Rght'), charIDToTypeID('#Pxl'), x + radius);
ref.putProperty(charIDToTypeID('Chnl'), charIDToTypeID('fsel'));
d2.putReference(charIDToTypeID('null'), ref);
d2.putObject(charIDToTypeID('T '), charIDToTypeID('Elps'), d1);
d2.putUnitDouble(charIDToTypeID('Fthr'), charIDToTypeID('#Pxl'), 0);
d2.putBoolean(charIDToTypeID('AntA'), true);
executeAction(charIDToTypeID('setd'), d2, DialogModes.NO);
return document.selection;
}
然后,您可以执行以下操作以满足您的要求:
// Example usage
var document = app.activeDocument;
var circleSelection = makeCircleSelection(200, 100, 100);
circleSelection.copy();
document.artLayers.add();
document.paste();
Note:您需要确保像素存在于从中复制的活动艺术层上的圆形 Select 中.该区域不能透明.