/// <summary> /// Saves to file. /// </summary> /// <param name="__docRef">Document</param> /// <param name="__args">Arguments</param> /// <param name="__selectionOnly">if set to <c>true</c> Export Selection Only</param> private void saveToFile(Photoshop.Document __docRef, string[] __args, bool __selectionOnly) { bool __exportLayerComps = false; int __compsCount; int __compsIndex; Photoshop.LayerComp __compRef; Photoshop.Document __duppedDocument; string __fileNameBody = null; bool __hasSelection; bool __exportFonts = false; Format __imageFormat; __exportLayerComps = __form.ExportLayerComps.Checked; //MessageBox.Show(__exportLayerComps.ToString()); bool __isNamedLayerComp = false; Photoshop.JPEGSaveOptions __jpgSaveOptions = null; try { __jpgSaveOptions = new Photoshop.JPEGSaveOptions(); __jpgSaveOptions.EmbedColorProfile = false; __jpgSaveOptions.FormatOptions = Photoshop.PsFormatOptionsType.psStandardBaseline; // 1 psStandardBaseline __jpgSaveOptions.Matte = Photoshop.PsMatteType.psNoMatte; // 1 psNoMatte } catch //(Exception __e) { DialogResult __dr = MessageBox.Show("Photoshop is busy with open dialog or something." + "\r\n" + "\r\n" + "Please switch to Photoshop then close open dialogs or leave editing state", "Photoshop not ready", MessageBoxButtons.OK); if (__dr == DialogResult.OK) { Application.Exit(); } } switch (__args[2 + __form.idx]) { case "jpg": __jpgSaveOptions.Quality = int.Parse(__args[4 + __form.idx]); if (__jpgSaveOptions.Quality == 12) { __exportFonts = true; } __imageFormat = Format.JPG; //__exportLayerComps = true; //force using this mode break; case "png": __imageFormat = Format.PNG; //__exportLayerComps = true; break; case "gif": __imageFormat = Format.GIF; break; case "pdf": __imageFormat = Format.PDF; __exportLayerComps = true; break; case "sc": __jpgSaveOptions.Quality = 12; __imageFormat = Format.JPG; __exportLayerComps = true; //force using this mode break; default: // Export each layer by its name __jpgSaveOptions.Quality = int.Parse(__args[4 + __form.idx]); __imageFormat = Format.JPG; break; } switch (__args[3 + __form.idx]) { case "name": __isNamedLayerComp = true; break; case "index": __isNamedLayerComp = false; break; default: __isNamedLayerComp = false; break; } Photoshop.ExportOptionsSaveForWeb __gifExportOptionsSaveForWeb = new Photoshop.ExportOptionsSaveForWeb(); //gifExportOptionsSaveForWeb.MatteColor = 255 __gifExportOptionsSaveForWeb.Format = Photoshop.PsSaveDocumentType.psCompuServeGIFSave; // 3; __gifExportOptionsSaveForWeb.ColorReduction = Photoshop.PsColorReductionType.psAdaptive; //1; __gifExportOptionsSaveForWeb.Colors = 256; __gifExportOptionsSaveForWeb.Dither = Photoshop.PsDitherType.psNoise; //3; __gifExportOptionsSaveForWeb.DitherAmount = 100; __gifExportOptionsSaveForWeb.Quality = 100; __gifExportOptionsSaveForWeb.Transparency = true; __gifExportOptionsSaveForWeb.TransparencyAmount = 100; __gifExportOptionsSaveForWeb.TransparencyDither = Photoshop.PsDitherType.psNoDither; //2; __gifExportOptionsSaveForWeb.IncludeProfile = false; __gifExportOptionsSaveForWeb.Lossy = 0; __gifExportOptionsSaveForWeb.WebSnap = 0; Photoshop.ExportOptionsSaveForWeb __pngExportOptionsSaveForWeb = new Photoshop.ExportOptionsSaveForWeb(); __pngExportOptionsSaveForWeb.Format = Photoshop.PsSaveDocumentType.psPNGSave; // 13; __pngExportOptionsSaveForWeb.PNG8 = false; __pngExportOptionsSaveForWeb.Transparency = true; Photoshop.PDFSaveOptions __pdfSaveOptions = new Photoshop.PDFSaveOptions(); __pdfSaveOptions.AlphaChannels = false; __pdfSaveOptions.Annotations = false; __pdfSaveOptions.DowngradeColorProfile = true; __pdfSaveOptions.EmbedColorProfile = true; __pdfSaveOptions.Encoding = Photoshop.PsPDFEncodingType.psPDFJPEG; __pdfSaveOptions.Interpolation = false; __pdfSaveOptions.JPEGQuality = 9; __pdfSaveOptions.Layers = false; __pdfSaveOptions.SpotColors = false; __pdfSaveOptions.Transparency = false; __pdfSaveOptions.UseOutlines = false; __pdfSaveOptions.VectorData = false; //MessageBox.Show(__args(3)) //MessageBox.Show(__imageType) __compsCount = __docRef.LayerComps.Count; //ActionSaveScreenSelection __asss = new ActionSaveScreenSelection(__docRef, __jpgSaveOptions); ActionSaveScreenSelection __asss = new ActionSaveScreenSelection(__docRef); __hasSelection = __asss.hasSelection; if (__asss.hasSelection) __asss.wipeOldScreens(); // Exporting layercomps by index or name if (__exportLayerComps) { if (__compsCount <= 1) { //Set textItemRef = appRef.ActiveDocument.Layers(1) //textItemRef.TextItem.Contents = Args.Item(1) //outFileName = Args.Item(1) if (__selectionOnly) // IF screen selection then save crop { if (__asss.count >= 1) { __asss.saveAll(); } } else { //MessageBox.Show(__args[1]); if (__imageFormat == Format.JPG) { __docRef.SaveAs(__args[1 + __form.idx], __jpgSaveOptions, true, null); } else if (__imageFormat == Format.PNG) { __fileNameBody = __docRef.Name.Substring(0, __docRef.Name.LastIndexOf(".")) + ".png"; //MessageBox.Show(__docRef.Path + __fileNameBody); __docRef.Export(__docRef.Path + __fileNameBody, 2, __pngExportOptionsSaveForWeb); if (__fileNameBody.Replace(" ", "-") != __fileNameBody) { if (File.Exists(__docRef.Path + __fileNameBody)) File.Delete(__docRef.Path + __fileNameBody); try { //MessageBox.Show(__fileNameBody.Replace(" ", "-")); File.Move(__docRef.Path + __fileNameBody.Replace(" ", "-"), __docRef.Path + __fileNameBody); } catch { } } } else if (__imageFormat == Format.PDF) { __fileNameBody = __docRef.Name.Substring(0, __docRef.Name.LastIndexOf(".")) + ".pdf"; __docRef.SaveAs(__docRef.Path + __fileNameBody, __pdfSaveOptions, false, Photoshop.PsExtensionType.psLowercase); } else { __fileNameBody = __docRef.Name.Substring(0, __docRef.Name.LastIndexOf(".")) + ".gif"; __docRef.Export(__docRef.Path + __fileNameBody, 2, __gifExportOptionsSaveForWeb); } } } else { //msgbox("comps!") for (__compsIndex = 1; __compsIndex <= __compsCount; __compsIndex++) { //MsgBox(docRef.LayerComps.Count) //End __compRef = __docRef.LayerComps[__compsIndex]; //if (exportInfo.selectionOnly && !compRef.selected) continue; // selected only __compRef.Apply(); //msgbox(compRef.Name) __duppedDocument = null; /*if (__hasSelection) { try { __duppedDocument = __docRef.Duplicate(null, null); } catch (Exception) { MessageBox.Show("Essayez de redémarrer UTC FMCore"); } if (__screenSelectionList.Count > 0) { if (__screenSelectionList.Contains(__compsIndex.ToString())) saveScreenSelection(__docRef, __duppedDocument, __compsIndex, __jpgSaveOptions); else __duppedDocument.Close(2); } else { saveScreenSelection(__docRef, __duppedDocument, __compsIndex, __jpgSaveOptions); } }*/ if (__selectionOnly) { if (__asss.count >= 1) { __asss.saveAll(__compsCount, __compsIndex); } } else { try { __duppedDocument = __docRef.Duplicate(null, null); } catch (Exception) { MessageBox.Show("Essayez de redémarrer UTC FMCore"); } if (!__isNamedLayerComp) { // cleaning single JPEG file if layer comps > 1 if (File.Exists(__docRef.Name.Substring(0, __docRef.Name.LastIndexOf(".")) + ".jpg")) { File.Delete(__docRef.Name.Substring(0, __docRef.Name.LastIndexOf(".")) + ".jpg"); } __fileNameBody = __docRef.Name.Substring(0, __docRef.Name.LastIndexOf(".")) + "." + __compsIndex; } else { __fileNameBody = __compRef.Name; } if (__imageFormat == Format.JPG) { __fileNameBody += ".jpg"; __duppedDocument.SaveAs(__docRef.Path + __fileNameBody, __jpgSaveOptions, true, null); } else if (__imageFormat == Format.PNG) { __fileNameBody += ".png"; //MessageBox.Show(__docRef.Path + __fileNameBody); __duppedDocument.Export(__docRef.Path + __fileNameBody, 2, __pngExportOptionsSaveForWeb); if (__fileNameBody.Replace(" ", "-") != __fileNameBody) { if (File.Exists(__docRef.Path + __fileNameBody)) File.Delete(__docRef.Path + __fileNameBody); try { File.Move(__docRef.Path + __fileNameBody.Replace(" ", "-"), __docRef.Path + __fileNameBody); } catch { } } } else if (__imageFormat == Format.PDF) { __fileNameBody += ".pdf"; //MessageBox.Show(__docRef.Path + __fileNameBody); //__duppedDocument.Export(__docRef.Path + __fileNameBody, 2, __pdfExportOptionsSaveForWeb); __duppedDocument.SaveAs(__docRef.Path + __fileNameBody, __pdfSaveOptions, false, Photoshop.PsExtensionType.psLowercase); } else { __fileNameBody += ".gif"; __duppedDocument.Export(__docRef.Path + __fileNameBody, 2, __gifExportOptionsSaveForWeb); } __duppedDocument.Close(2); } } __compRef = __docRef.LayerComps[1]; __compRef.Apply(); } //MsgBox(Me.AutoArchive.Checked) archiveFiles(__docRef); FileInfo __selectedfile = new FileInfo(__docRef.Name); string __selectedfileext = __selectedfile.Extension; //MessageBox.Show(__selectedfile.Extension); List<string> __allowedext = new List<string>(new string[] { ".psd", ".psb" }); if (__allowedext.Contains(__selectedfile.Extension.ToLower()) && __exportFonts) listFonts(__docRef, __docRef.Name, true); } else //Exporting each layers by name { Photoshop.ArtLayer __layer; for (__compsIndex = 1; __compsIndex <= __docRef.ArtLayers.Count; __compsIndex++) { __layer = __docRef.ArtLayers[__compsIndex]; //isVisible = oLayer.visible __appRef.ActiveDocument.ActiveLayer = __layer; //oLayer.Apply() //duppedDocument = docRef.Duplicate() //msgbox(compRef.Name) __fileNameBody = (string)(__layer.Name + ".jpg"); //msgbox(fileNameBody) __docRef.SaveAs(__docRef.Path + __fileNameBody, __jpgSaveOptions, true, null); __layer.Visible = false; __appRef.ActiveDocument.ActiveLayer = __layer; //duppedDocument.Close(2) } } //ExportImagesRights() if (__compsCount > 0) { __compRef = __docRef.LayerComps[1]; __compRef.Apply(); } }
/// <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); }
public void Save(ref ps.Document doc, FileInfo file) { // Save png for web format ps.EPSSaveOptionsClass SaveOpts = new ps.EPSSaveOptionsClass(); SaveOpts.Preview = _preview; SaveOpts.VectorData = _vectorData; SaveOpts.Interpolation = true; SaveOpts.Encoding = ps.PsSaveEncoding.psJPEGMedium; doc.SaveAs(file.FullName, SaveOpts, true, ps.PsExtensionType.psLowercase); }
private void saveSelection(Photoshop.Document __duppedDocument, int __count, int __idx, int __subindex) { string __fileNameBody; string __sidx = string.Empty; if (__subindex > 0) __sidx = "." + __subindex; __fileNameBody = (__doc.Name.LastIndexOf(".") > -1) ? __doc.Name.Substring(0, __doc.Name.LastIndexOf(".")) : __doc.Name; __fileNameBody += (__count <= 1) ? "" : "." + __idx + __sidx + ""; __fileNameBody += ".png"; if (!Directory.Exists(__doc.Path + "/+ Screens/")) Directory.CreateDirectory(__doc.Path + "/+ Screens/"); __duppedDocument.SaveAs(__doc.Path + "/+ Screens/" + __fileNameBody, __saveOptions, true, null); }
public void Save(ref ps.Document doc, FileInfo file) { // Save png for web format ps.TiffSaveOptionsClass SaveOpts = new ps.TiffSaveOptionsClass(); SaveOpts.AlphaChannels = _alphaChannel; SaveOpts.Annotations = _annotations; SaveOpts.ByteOrder = _byteOrder; SaveOpts.JPEGQuality = _jpgQuality; SaveOpts.LayerCompression = _layerCompression; SaveOpts.Layers = _layers; SaveOpts.SpotColors = _spotColors; SaveOpts.Transparency = _transparency; doc.SaveAs(file.FullName, SaveOpts, true, ps.PsExtensionType.psLowercase); }