Skip to content Skip to sidebar Skip to footer

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 tuple = new Tuple

Solution 1:

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.

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

Solution 2:

According to this page the add method requires an array. 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


Post a Comment for "C# Equivalent To This Code"