C#等效于此代码

问题描述:

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);

但不为我工作.知道吗??

but not working for me. Any idea ??

我上了课

 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();

its not working either i have to pass it as an argument to the Colorsamples.Add();

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

我快速浏览了互操作,并且 Add 方法使用了一个对象.就像@icbytes暗示的那样,它需要一个数组,因此您可能可以摆脱一组装箱的对象.互操作程序全部使用double(而不是float),因此double可能是您要使用的类型.

I had a quick look at the interop and the Add method takes an object. As @icbytes implies, it takes an array so you could probably get away with an array of boxed objects. The interop uses double (not float) all over so double is probably the type you want to use.

出于好奇心,您应该遍历ColorSamplers集合,并查看其中包含哪些底层类型.该集合存储实现ColorSampler(包含SolidColorClass属性的对象),因此,如果您知道哪些对象实现了该目标,则可以创建那些类型以传递给 Add 方法.

For you own curiosity you should loop through the ColorSamplers collection and see what underlying types there are contained inside it. The collection stores objects that implement ColorSampler (which contains a SolidColorClass property) so if you know what objects implement this you can create those types to pass into the Add method.

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

Set the preference to pixels first to assume all values you provide are pixel-based.

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 } );