C#等效于此代码

时间:2013-10-04 09:24:16

标签: c# javascript photoshop

var xPos = new UnitValue( 0.5,'px') ;
var yPos = new UnitValue( 0.5,'px');
var pixPos = [ xPos, yPos ];

我用过这个

Tuple<PsUnits, PsUnits> tuple = new Tuple<PsUnits,PsUnits>(xpos,ypos);

但不适合我。有什么想法??

我上了课

 public class pixpos
  {
    float XPOS;
    float YPOS;
    public float xpos
    {
        get
        {
            return this.XPOS;
        }
        set
        {
            this.XPOS = value;
        }
    }
    public float ypos
    {
        get { return this.YPOS; }
        set { this.YPOS = value; }
    }
}   
     pixpos obj = new pixpos();
                    obj.xpos = xPos;
                    obj.ypos = yPos;

它不起作用我必须将它作为参数传递给Colorsamples.Add();

 Photoshop.Application appRef = default(Photoshop.Application);
var mySampler = appRef.ActiveDocument.ColorSamplers.Add(ps);

2 个答案:

答案 0 :(得分:2)

我快速查看了互操作,添加方法获取了一个对象。正如@icbytes所暗示的那样,它需要一个数组,所以你可能会得到一个盒装对象数组。互操作使用double(不是float),因此double可能是您要使用的类型。

为了您自己的好奇心,您应该遍历ColorSamplers集合并查看其中包含的基础类型。该集合存储实现ColorSampler(包含SolidColorClass属性)的对象,因此,如果您知道哪些对象实现了此属性,则可以创建这些类型以传递到 Add 方法。 / p>

首先将首选项设置为像素,假设您提供的所有值都是基于像素的。

Photoshop.Application appRef = default(Photoshop.Application);
appRef.Preferences.RulerUnits = PsUnits.psPixels;

foreach (ColorSampler sampler in appRef.ActiveDocument.ColorSamplers)
{
  // Check to see what underlying type a sampler is so you can try
  // and make instances of this to pass into the Add method.
  Console.WriteLine(sampler.GetType().FullName);
}

// Try add an object array of double values, based on the error message implied units could work.
// 'D' with convert the number literal to a 'double'.
appRef.ActiveDocument.ColorSamplers.Add(new object[] { 0.5D, 0.5D } );

答案 1 :(得分:0)

根据此页面,add方法需要一个数组。将参数传递为其他任何东西肯定会导致崩溃/异常:

http://cssdk.adobesites.com/sdk/1.0/docs/WebHelp/references/csawlib/com/adobe/photoshop/ColorSamplers.html