private void ProcessPhotoshop() { app = new ApplicationClass { Visible = false }; _jpegSaveOptions = new JPEGSaveOptions { FormatOptions = PsFormatOptionsType.psStandardBaseline, Matte = PsMatteType.psNoMatte, Quality = _OutMgr.Quality }; // Store the current rulerUnits for later. We're going to change // it to pixels for now, and we want to change it back later. var myRulerUnits = app.Preferences.RulerUnits; //https://forums.adobe.com/thread/1246514 // Set rulerUnits to pixels app.Preferences.RulerUnits = PsUnits.psPixels; foreach (var file in _OutMgr.GetAllFiles()) { SplitPicture(file); } // Reset the ruler units app.Preferences.RulerUnits = myRulerUnits; app.Quit(); }
static void PhotoshopJob(ref Application photoshop) { try { string status = ""; while (status != "done") { Thread.Sleep(1000); status = photoshop.ActiveDocument.Info.Keywords[0].ToString(); Console.WriteLine(status); } Console.WriteLine(photoshop.Documents.Count.ToString() + " " + status); JPEGSaveOptions saveOptions = new JPEGSaveOptions(); saveOptions.EmbedColorProfile = true; saveOptions.FormatOptions = PsFormatOptionsType.psStandardBaseline; saveOptions.Matte = PsMatteType.psNoMatte; saveOptions.Quality = 12; photoshop.ActiveDocument.SaveAs(@"C:\Users\Dude\Documents\00.jpg", saveOptions, true, PsExtensionType.psLowercase); photoshop.ActiveDocument.Close(PsSaveOptions.psDoNotSaveChanges); Thread.CurrentThread.Abort(); } catch { if (PhotoshopThread.ThreadState != ThreadState.AbortRequested) { Console.WriteLine(PhotoshopThread.ThreadState.ToString()); Start(ref photoshop); } } }
/// <summary> /// 保存JPG文件 /// </summary> /// <param name="path"></param> public void SaveJpg(string path) { path = ExistPath(path); var docref = app.ActiveDocument; var name = docref.Name; var saveOptions = new JPEGSaveOptions(); saveOptions.EmbedColorProfile = true; saveOptions.Quality = 10; Console.WriteLine(path + name); docref.SaveAs(path + name, saveOptions, false, PsExtensionType.psLowercase); }
private void SaveJpegDocument(string jpgFilename) // Page 32 { PsUnits originalRulerUnits = appRef.Preferences.RulerUnits; appRef.Preferences.RulerUnits = PsUnits.psPixels; JPEGSaveOptions myJPEGOptions = new JPEGSaveOptions(); myJPEGOptions.EmbedColorProfile = true; myJPEGOptions.FormatOptions = PsFormatOptionsType.psStandardBaseline; myJPEGOptions.Matte = PsMatteType.psNoMatte; myJPEGOptions.Quality = 1; appRef.ActiveDocument.SaveAs(jpgFilename, myJPEGOptions, true, PsExtensionType.psLowercase); }
public static void RunAction(string orig, string target, string actionFileName, string action, string group) { ApplicationClass app = new ApplicationClass(); app.DisplayDialogs = PsDialogModes.psDisplayNoDialogs; //app.Load(actionFileName); var doc = app.Open(orig); app.DoAction(action, group); var options = new JPEGSaveOptions(); options.Quality = 9; doc.SaveAs(target, options, true, PsExtensionType.psLowercase); doc.Close(PsSaveOptions.psDoNotSaveChanges); //doc.Close(PsSaveOptions.psSaveChanges); }
/** * 处理明信片信息 */ public static FileInfo Process(this FileInfo sourceFileInfo, PostCardProcessCropInfo postCardProcessCropInfo, string frontStyle, int productWidth, int productHeight) { if (sourceFileInfo.Directory != null && !sourceFileInfo.Directory.Exists) { Directory.CreateDirectory(sourceFileInfo.Directory.FullName); } try //尝试打开,如果打不开进行标记 { var photoShopOperation = new PhotoShopOperation(sourceFileInfo); var myDoc = photoShopOperation.OpenDocument(); //如果色彩模式不是CMYK、RGB、灰度的话,转化为CMYK模式 if ((myDoc.Mode != PsDocumentMode.psCMYK) && (myDoc.Mode != PsDocumentMode.psRGB) && (myDoc.Mode != PsDocumentMode.psGrayscale)) { myDoc.ChangeMode(PsChangeMode.psConvertToCMYK); } if (( myDoc.Width > myDoc.Height && postCardProcessCropInfo.ImageWidth < postCardProcessCropInfo.ImageHeight ) || ( myDoc.Width < myDoc.Height && postCardProcessCropInfo.ImageWidth > postCardProcessCropInfo.ImageHeight )) { LogInfo.Info("方向不正确,向右旋转90°"); postCardProcessCropInfo.Rotation = (postCardProcessCropInfo.Rotation + 90) % 360; } myDoc.RotateCanvas(postCardProcessCropInfo.Rotation); myDoc.ResizeImage(null, null, 300); //切换到点 photoShopOperation.SwitchRuler(PsUnits.psPoints); var pictureSize = new Size(productWidth, productHeight); switch (frontStyle) { case "A": pictureSize.Width -= 10; pictureSize.Height -= 10; break; case "C": pictureSize.Width = pictureSize.Height = Math.Min(pictureSize.Height, pictureSize.Width) - 10; break; default: pictureSize.Width = pictureSize.Width; pictureSize.Height = pictureSize.Height; //默认不进行处理 break; } var cutRight = myDoc.Width * (+postCardProcessCropInfo.CropWidth + postCardProcessCropInfo.CropLeft); var cutWidth = myDoc.Width * postCardProcessCropInfo.CropWidth; var cutHeight = myDoc.Height * postCardProcessCropInfo.CropHeight; var cutBottom = myDoc.Height * (postCardProcessCropInfo.CropTop + postCardProcessCropInfo.CropHeight); myDoc.ResizeCanvas(cutRight, cutBottom, PsAnchorPosition.psTopLeft); myDoc.ResizeCanvas(cutWidth, cutHeight, PsAnchorPosition.psBottomRight); //切换到厘米 photoShopOperation.SwitchRuler(PsUnits.psMM); myDoc.ResizeImage(pictureSize.Width, pictureSize.Height); //photoShopOperation.Cut(cutLeft, cutTop, cutRight, cutBottom, pictureSize.Width, pictureSize.Height, 300); if (frontStyle == "C") { //增加白边到成品尺寸的A版 myDoc.ResizeCanvas(productWidth - 10, productHeight - 10, PsAnchorPosition.psTopLeft); } //将文件大小修改为成品尺寸,图像居中 myDoc.ResizeCanvas(productWidth, productHeight); //切换到厘米 photoShopOperation.SwitchRuler(PsUnits.psPoints); myDoc.Selection.SelectAll(); // // var solidColor = new SolidColor // { // CMYK = new CMYKColor // { // Cyan = 0, // Magenta = 0, // Yellow = 0, // Black = 40 // } // }; // myDoc.Selection.Stroke(solidColor, 1, Opacity: 100); //切换到厘米 photoShopOperation.SwitchRuler(PsUnits.psMM); var myJpegSaveOption = new JPEGSaveOptions { Quality = 12, Matte = PsMatteType.psNoMatte, FormatOptions = PsFormatOptionsType.psStandardBaseline }; try { photoShopOperation.Application.DoJavaScript( "executeAction(charIDToTypeID( \"FltI\" ), undefined, DialogModes.NO );"); } catch { // ignored } foreach (Channel orange in myDoc.Channels) { if (orange.Visible == false) { orange.Delete(); } } var fileInfo = new FileInfo(sourceFileInfo.FullName + ".tmp.jpg"); myDoc.SaveAs(fileInfo.FullName, myJpegSaveOption); photoShopOperation.ResetRuler(); myDoc.Close(); return(fileInfo); } catch (Exception e) { Console.WriteLine(e); return(null); } }