简体   繁体   English

C# 相当于此代码

[英]C# Equivalent to this code

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

I have used this我用过这个

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

but not working for me.但不适合我。 Any idea ??任何的想法 ??

I made a class我做了一堂课

 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;

its not working either i have to pass it as an argument to the Colorsamples.Add();它不起作用,我必须将它作为参数传递给Colorsamples.Add();

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

I had a quick look at the interop and the Add method takes an object.我快速浏览了互操作, Add方法接受一个对象。 As @icbytes implies, it takes an array so you could probably get away with an array of boxed objects.正如@icbytes 暗示的那样,它需要一个数组,因此您可能会使用一组装箱对象。 The interop uses double (not float ) all over so double is probably the type you want to use.互操作使用double (而不是float ),所以double可能是您想要使用的类型。

For you own curiosity you should loop through the ColorSamplers collection and see what underlying types there are contained inside it.为了您自己的好奇心,您应该遍历 ColorSamplers 集合并查看其中包含哪些底层类型。 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.该集合存储实现ColorSampler (其中包含SolidColorClass属性)的对象,因此如果您知道哪些对象实现了它,您可以创建这些类型以传递给Add方法。

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

According to this page the add method requires an array.根据this page add 方法需要一个数组。 Passing the argument as anything else surely will cause a crash/exception:将参数作为其他任何内容传递肯定会导致崩溃/异常:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM