javascript Photoshop 脚本:将图像移动到位置 x,y
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12064015/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Photoshop scripting: Move an image to position x,y
提问by Max Kielland
I have an active ArtLayer
referenced by the variable NewLayer
that I want to move to the absolute position x,y in the canvas.
我有一个ArtLayer
由变量引用的活动NewLayer
,我想移动到画布中的绝对位置 x,y。
I have been googling for a couple of hours now without any results. Can some one please give an example?
我已经在谷歌上搜索了几个小时没有任何结果。有人可以举个例子吗?
// Thanks.
// 谢谢。
回答by Max Kielland
After some more API reading and searching I came to the conclusion that it is only possible to move a layer with delta move.
在更多的 API 阅读和搜索之后,我得出的结论是,只能使用 delta move 移动图层。
I wrote this little function to position a layer at an absolute position. Hope this is helpful to the next reader with the same question...
我编写了这个小函数来将图层定位在绝对位置。希望这对下一个有同样问题的读者有所帮助......
//******************************************
// MOVE LAYER TO
// Author: Max Kielland
//
// Moves layer fLayer to the absolute
// position fX,fY. The unit of fX and fY are
// the same as the ruler setting.
function MoveLayerTo(fLayer,fX,fY) {
var Position = fLayer.bounds;
Position[0] = fX - Position[0];
Position[1] = fY - Position[1];
fLayer.translate(-Position[0],-Position[1]);
}