سؤال

I have a problem with COM compatibility issues. This link was already very helpful, COM interface Photoshop compatibility issue, explaining that COM compatibility issues can be fixed with late binding. I’ve tried this but I am now confused on how to use types that I used to access via the COM object.

Original code:

//This works with late binding
m_Application = new Photoshop.Application();
var refe = new Photoshop.ActionReference();

refe.PutProperty(m_Application.CharIDToTypeID("Prpr"), m_Application.CharIDToTypeID("NmbL"));

//This is the problem area
var ColorlendMode = Photoshop.PsBlendMode.psColorBlend;

var visibleLayers = new List<Photoshop.ArtLayer>();

Late binding code:

//works...
dynamic m_Application = Activator.CreateInstance(Type.GetTypeFromProgID("Photoshop.Application"));
dynamic refe = Activator.CreateInstance(Type.GetTypeFromProgID("Photoshop.ActionReference"));

refe.PutProperty(m_Application.CharIDToTypeID("Prpr"), m_Application.CharIDToTypeID("NmbL"));

//PROBLEM:
//Doesn't compile
Type BlendModeType = Type.GetTypeFromProgID("Photoshop.PsBlendMode").psColorBlend;

//returns null
//Type BlendModeType = Type.GetTypeFromProgID("Photoshop.PsBlendMode");
//Type artLayerType = Type.GetTypeFromProgID("Photoshop.ArtLayer");

The compile erorr is:

'System.Type' does not contain a definition for 'psColorBlend'

So how do I get the enum PsBlendMode that I used to get with the Photoshop COM object (added as Reference in my project)?

هل كانت مفيدة؟

المحلول 2

Ok different idea:

Just define your own enum to represent PSColorBlen and use that

public enum PsBlendMode
{
    psColorBlend = 22
}

var ColorlendMode = PsBlendMode.psColorBlend;

You may have to cast to an int when you pass it into a call.

See here for a list of the constant values: http://fs.mis.kuas.edu.tw/~wchsieh/photoshopy9.py

نصائح أخرى

Try this code .. you will getting the blend mode Name as String type..

 Public Enum EBlendModes
    None = 0
    psSoftLight = 13
    psScreen = 9
    psNormalBlend = 2
    psMultiply = 5
    psColorBurn = 6
    psDissolve = 3
    psHardMix = 26
    psHardLight = 14
    psDarken = 4
    psDifference = 18
    psColorBlend = 22
    psPinLight = 17
    psOverlay = 12
    psVividLight = 15
    psLighterColor = 27
    psLinearLight = 16
    psDarkerColor = 28
    psLinearDodge = 11
    psLinearBurn = 7
    psExclusion = 19
    psLuminosity = 23
    psSubtract = 29
    psPassThrough = 1
    psColorDodge = 10
    psDivide = 30
    psSaturationBlend = 21
    psLighten = 8
    psHue = 20
End Enum
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Try
        Dim _appref = Activator.CreateInstance(Type.GetTypeFromProgID("Photoshop.Application"))
        Dim _blndmod As EBlendModes = CInt(_appref.activedocument.Activelayer.blendmode)
        MsgBox(_blndmod.ToString)
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub

Result is : PsNormalBlend.... are u expecting like this.............

I don't think you can do what you are trying to do for enums. The closest you can do will be to loop through the enums using reflection to find the one you want as a string.

See this: http://www.codeproject.com/Tips/550160/Getting-enum-value-from-another-class-via-Reflecti

Try running this and see if it prints out the value for psColorBlend:

var fieldsArray = Type.GetTypeFromProgID("Photoshop.PsBlendMode").GetFields(BindingFlags.Public | BindingFlags.Static);

foreach (var fInfo in fieldsArray)
{
    var ulngValue = (ulong)Convert.ChangeType(fInfo.GetValue(null), typeof(ulong));
    Console.WriteLine(fInfo.Name.ToString(CultureInfo.InvariantCulture) + " : " + ulngValue.ToString(CultureInfo.InvariantCulture));
}  

you can not get the blend mode value without any document or without select any layer... you must be select a layer and then you can get the BlendMode value otherwise you can not.. because BlendMode is an "Artlayer{Interface}" properties

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top