簡體   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 ];

我用過這個

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

我快速瀏覽了互操作, Add方法接受一個對象。 正如@icbytes 暗示的那樣,它需要一個數組,因此您可能會使用一組裝箱對象。 互操作使用double (而不是float ),所以double可能是您想要使用的類型。

為了您自己的好奇心,您應該遍歷 ColorSamplers 集合並查看其中包含哪些底層類型。 該集合存儲實現ColorSampler (其中包含SolidColorClass屬性)的對象,因此如果您知道哪些對象實現了它,您可以創建這些類型以傳遞給Add方法。

首先將首選項設置為像素以假設您提供的所有值都是基於像素的。

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

根據this page add 方法需要一個數組。 將參數作為其他任何內容傳遞肯定會導致崩潰/異常:

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