/// <summary> /// Magic Wand selection /// </summary> /// <param name="app">Photoshop Application Object</param> /// <param name="x">x-Axis pixel source selection</param> /// <param name="y">y-Axis pixel source selection</param> /// <param name="tolerance"> Selection tolerance</param> /// <param name="antiAlias"> Anti-Alias option</param> /// <param name="contiguous"></param> /// <param name="mergedLayer"></param> public static void MagicWand(ps.ApplicationClass app,int x, int y, int tolerance = 32, bool antiAlias = true, bool contiguous = false, bool mergedLayer = false) { // Action recorded on photoshop and transcripted by the Action Listener script // This code is the result of the Action Listener script ps.ActionDescriptorClass desc = new ps.ActionDescriptorClass(); ps.ActionReferenceClass refe = new ps.ActionReferenceClass(); refe.PutProperty((int)cst.phClassChannel, (int)cst.phKeySelection); desc.PutReference((int)cst.phClassNull, refe); ps.ActionDescriptorClass positionDesc = new ps.ActionDescriptorClass(); positionDesc.PutUnitDouble((int)cst.phEnumHorizontal, (int)cst.phUnitDistance, x); positionDesc.PutUnitDouble((int)cst.phEnumVertical, (int)cst.phUnitDistance, y); desc.PutObject((int)cst.phKey_Source, (int)cst.phClassPoint, positionDesc); desc.PutInteger((int)cst.phKeyTolerance, tolerance);// tolerance desc.PutBoolean((int)cst.phEnumMerged, mergedLayer);// sample all layers desc.PutBoolean((int)cst.phKeyContiguous, contiguous);// contiguous desc.PutBoolean((int)cst.phClassAntiAliasedPICTAcquire, antiAlias);// anti-alias app.ExecuteAction((int)cst.phEventSet, desc, ps.PsDialogModes.psDisplayNoDialogs); }
/// <summary> /// Determine if the background of the document is transparent /// </summary> /// <param name="app">Photoshop Application Object</param> /// <param name="doc">Photoshop Document Object</param> /// <returns>if document background is transparent </returns> public static bool IsTransparent(ref ps.ApplicationClass app,ref ps.Document doc) { //Make Transparent pixels as selection var desc = new ps.ActionDescriptorClass(); var ref1 = new ps.ActionReferenceClass(); ref1.PutProperty((int)cst.phClassChannel, (int)cst.phKeySelection); desc.PutReference((int)cst.phClassNull, ref1); var ref2 = new ps.ActionReferenceClass(); ref2.PutEnumerated((int)cst.phClassChannel, (int)cst.phClassChannel, (int)cst.phEnumTransparency); desc.PutReference((int)cst.phKey_Source, ref2); app.ExecuteAction((int)cst.phEventSet, desc, ps.PsDialogModes.psDisplayNoDialogs); // Verify if the Selection is consistent if (doc.Selection.Solid) { Deselect(ref doc); ; return false; } else { Deselect(ref doc); return true; } }