Esempio n. 1
0
 /// <summary>
 /// Closes the document.
 /// </summary>
 /// <param name="__docRef">Document refrence</param>
 private void closeDocument(Photoshop.Document __docRef)
 {
     if (!__keepOpen)
     {
         __docRef.Close(2);
     }
 }
 public void Close(ref ps.Document doc)
 {
     doc.Close(ps.PsSaveOptions.psDoNotSaveChanges);
 }
Esempio n. 3
0
        /// <summary>
        /// Saves the screen selection.
        /// </summary>
        /// <param name="__docRef">Document Refrence</param>
        /// <param name="__doc">Document</param>
        /// <param name="__idx">Layer Comp Index</param>
        /// <param name="__options">JPEG options</param>
        private void saveScreenSelection(Photoshop.Document __docRef, Photoshop.Document __doc, int __idx, Photoshop.JPEGSaveOptions __options)
        {
            Photoshop.Channel __selChannel;
            object __selBounds;
            string __fileNameBody;
            bool __hasSelection = false;
            Photoshop.ActionDescriptor __desc = new Photoshop.ActionDescriptor();
            Photoshop.ActionReference __ref = new Photoshop.ActionReference();
            Photoshop.ArtLayer __layer;
            int __j;

            try
            {
                __selChannel = getScreenSelectionChannel(__doc);
                __hasSelection = true;
                //MessageBox.Show(__selChannel.Name)
                __doc.Selection.Load(__selChannel, null, null);
                __selBounds = __doc.Selection.Bounds;
                __doc.Crop(__selBounds, null, null, null);
            }
            catch (Exception)
            {
                __hasSelection = false;

            }
            if (!__hasSelection)
            {
                /*try
                {

                    __ref.PutName(__appRef.CharIDToTypeID("Lyr "), "@screen");
                    __desc.PutReference(__appRef.CharIDToTypeID("null"), __ref);
                    __desc.PutEnumerated(__appRef.StringIDToTypeID("selectionModifier"), __appRef.StringIDToTypeID("selectionModifierType"), __appRef.StringIDToTypeID("removeFromSelection"));
                    __desc.PutBoolean(__appRef.CharIDToTypeID("MkVs"), true);
                    //__appRef.ExecuteAction(__appRef.CharIDToTypeID("slct"), __desc, Photoshop.PsDialogModes.psDisplayNoDialogs);
                    __desc = __appRef.ExecuteActionGet(__ref);

                    //__layer = (Photoshop.ArtLayer)__docRef.ActiveLayer;
                    //__selBounds = __layer.Bounds;
                    //__doc.Crop(__selBounds, null, null, null);
                    //__hasSelection = true;

                    string __res = __desc.GetString(__appRef.CharIDToTypeID("Nm  "));

                    if (__res == "@screen")
                    {
                        //int __index = __desc.GetInteger(__appRef.CharIDToTypeID("ItmI"));
                        MessageBox.Show(__desc.GetReference(__appRef.CharIDToTypeID("ItmI")).ToString());

                        //__docRef.ActiveLayer = __docRef.ArtLayers[__index];
                        //MessageBox.Show(__index.ToString());
                        //__layer = (Photoshop.ArtLayer)__doc.ArtLayers[__index];
                        //__selBounds = __layer.Bounds;
                        //__doc.Crop(__selBounds, null, null, null);
                        __hasSelection = true;
                    }
                    else
                    {
                        __hasSelection = false;
                    }
                }
                catch (Exception __e)
                {
                    MessageBox.Show(__e.Message);
                    __hasSelection = false;
                }
                */

                for (__j = 1; __j <= __docRef.Layers.Count; __j++)
                {
                    try
                    {
                        __layer = (Photoshop.ArtLayer)__docRef.Layers[__j];
                        //MessageBox.Show(__layer.Name);
                        if (__layer.Name == "@screen")
                        {
                            __selBounds = __layer.Bounds;
                            __doc.Crop(__selBounds, null, null, null);
                            __hasSelection = true;
                            break;
                        }
                    }
                    catch
                    {
                        __hasSelection = false;
                    }
                }
            }

            if (__hasSelection)
            {
                __fileNameBody = (__docRef.Name.LastIndexOf(".") > -1) ? __docRef.Name.Substring(0, __docRef.Name.LastIndexOf(".")) : __docRef.Name;
                __fileNameBody += (__idx <= -1) ? "_screen" : "." + __idx + "_screen";
                __fileNameBody += ".jpg";
                __doc.SaveAs(__docRef.Path + __fileNameBody, __options, true, null);
            }
            else
            {
                MessageBox.Show("You have to create a selection named \"screen\" or a layer named \"@screen\"", "No selection found", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                Application.Exit();
            }

            if (__idx > 0)
                __doc.Close(2);
        }