原創|產品更新|編輯:李顯亮|2020-08-03 11:29:14.820|閱讀 320 次
概述:Aspose.PSD for .Net更新至新版本v20.7,支持LnkE資源,支持britResource(亮度/對比度調整層資源),嘗試打開不支持的格式作為圖像時更改異常消息,歡迎下載體驗。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Aspose.PSD for .Net是高級PSD和入門級AI文件格式操作API,允許創建和編輯Photoshop文件,并提供更新圖層屬性,添加水印,執行圖形操作或將一種文件格式轉換為另一種文件的功能,沒有任何Adobe Photoshop或Adobe Illustrator依賴項。
令人興奮的是,.NET版Aspose.PSD迎來了v20.7的最新更新!新增了如下兩大新功能和1個增強:
>>你可以點擊這里下載Aspose.PSD for .NET v20.7測試體驗
key | 概述 | 類別 |
---|---|---|
PSDNET-673 | 支持LnkE資源 | 新功能 |
PSDNET-392 | 支持britResource(亮度/對比度調整層資源) | 新功能 |
PSDNET-629 | 嘗試打開不支持的格式作為圖像時更改異常消息 | 增強功能 |
PSDNET-594 | 無法保存LayerMask | Bug修復 |
PSDNET-597 | 如果在創建新的圖層組后保存PSD文件,則會在文件打開時收到Photoshop警告 | Bug修復 |
PSDNET-618 | 剪貼蒙版不適用于該文件夾 | Bug修復 |
PSDNET-625 | 無法使用Aspose.PSD for .NET打開文件 | Bug修復 |
PSDNET-650 | 將PSD轉換為PDF時圖像保存失敗異常 | Bug修復 |
PSDNET-655 | rop操作使PSD圖像中的剪切路徑無效 | Bug修復 |
PSDNET-662 | 嘗試使用陰影效果保存特定的PSD文件時出現NullReference異常 | Bug修復 |
PSDNET-666 | Aspose.PSD在Image.CanLoad(pdfStream)上返回true | Bug修復 |
PSDNET-676 | 圖層無法在生成的PNG中渲染 | Bug修復 |
PSDNET-677 | 訪問TextData的異常 | Bug修復 |
PSDNET-679 | ImageSaveException關于保存PSD | Bug修復 |
void AssertAreEqual(object expected, object actual) { if (!object.Equals(actual, expected)) { throw new FormatException(string.Format("Actual value {0} are not equal to expected {1}.", actual, expected)); } } object[] Lnk2ResourceSupportCases = new object[] { new object[] { "00af34a0-a90b-674d-a821-73ee508c5479", "rgb8_2x2.png", "png", string.Empty, 0x53, 0d, string.Empty, 7, true, 0x124L, 0x74cL } }; object[] LayeredLnk2ResourceSupportCases = new object[] { new object[] { "69ac1c0d-1b74-fd49-9c7e-34a7aa6299ef", "huset.jpg", "JPEG", string.Empty, 0x9d46, 0d, "xmp.did:0F94B342065B11E395B1FD506DED6B07", 7, true, 0x9E60L, 0xc60cL }, new object[] { "5a7d1965-0eae-b24e-a82f-98c7646424c2", "panama-papers.jpg", "JPEG", string.Empty, 0xF56B, 0d, "xmp.did:BDE940CBF51B11E59D759CDA690663E3", 7, true, 0xF694L, 0x10dd4L }, }; object[] LayeredLnk3ResourceSupportCases = new object[] { new object[] { "2fd7ba52-0221-de4c-bdc4-1210580c6caa", "panama-papers.jpg", "JPEG", string.Empty, 0xF56B, 0d, "xmp.did:BDE940CBF51B11E59D759CDA690663E3", 7, true, 0xF694l, 0x10dd4L }, new object[] { "372d52eb-5825-8743-81a7-b6f32d51323d", "huset.jpg", "JPEG", string.Empty, 0x9d46, 0d, "xmp.did:0F94B342065B11E395B1FD506DED6B07", 7, true, 0x9E60L, 0xc60cL }, }; var basePath = @"PSDNET392_1\"; const string Output = "Output\\"; // Saves the data of a smart object in PSD file to a file. void SaveSmartObjectData(string prefix, string fileName, byte[] data) { var filePath = basePath + prefix + "_" + fileName; using (var container = FileStreamContainer.CreateFileStream(filePath, false)) { container.Write(data); } } // Loads the new data for a smart object in PSD file. byte[] LoadNewData(string fileName) { using (var container = FileStreamContainer.OpenFileStream(basePath + fileName)) { return container.ToBytes(); } } // Gets and sets properties of the PSD Lnk2 / Lnk3 Resource and its liFD data sources in PSD image void ExampleOfLnk2ResourceSupport( string fileName, int dataSourceCount, int length, int newLength, object[] dataSourceExpectedValues) { using (PsdImage image = (PsdImage)Image.Load(basePath + fileName)) { Lnk2Resource lnk2Resource = null; foreach (var resource in image.GlobalLayerResources) { lnk2Resource = resource as Lnk2Resource; if (lnk2Resource != null) { AssertAreEqual(lnk2Resource.DataSourceCount, dataSourceCount); AssertAreEqual(lnk2Resource.Length, length); AssertAreEqual(lnk2Resource.IsEmpty, false); for (int i = 0; i < lnk2Resource.DataSourceCount; i++) { LiFdDataSource lifdSource = lnk2Resource[i]; object[] expected = (object[])dataSourceExpectedValues[i]; AssertAreEqual(LinkDataSourceType.liFD, lifdSource.Type); AssertAreEqual(new Guid((string)expected[0]), lifdSource.UniqueId); AssertAreEqual(expected[1], lifdSource.OriginalFileName); AssertAreEqual(expected[2], lifdSource.FileType.TrimEnd(' ')); AssertAreEqual(expected[3], lifdSource.FileCreator.TrimEnd(' ')); AssertAreEqual(expected[4], lifdSource.Data.Length); AssertAreEqual(expected[5], lifdSource.AssetModTime); AssertAreEqual(expected[6], lifdSource.ChildDocId); AssertAreEqual(expected[7], lifdSource.Version); AssertAreEqual((bool)expected[8], lifdSource.HasFileOpenDescriptor); AssertAreEqual(expected[9], lifdSource.Length); if (lifdSource.HasFileOpenDescriptor) { AssertAreEqual(-1, lifdSource.CompId); AssertAreEqual(-1, lifdSource.OriginalCompId); lifdSource.CompId = int.MaxValue; } SaveSmartObjectData( Output + fileName, lifdSource.OriginalFileName, lifdSource.Data); lifdSource.Data = LoadNewData("new_" + lifdSource.OriginalFileName); AssertAreEqual(expected[10], lifdSource.Length); lifdSource.ChildDocId = Guid.NewGuid().ToString(); lifdSource.AssetModTime = double.MaxValue; lifdSource.FileType = "test"; lifdSource.FileCreator = "me"; } AssertAreEqual(newLength, lnk2Resource.Length); break; } } AssertAreEqual(true, lnk2Resource != null); if (image.BitsPerChannel < 32) // 32 bit per channel saving is not supported yet { image.Save(basePath + Output + fileName, new PsdOptions(image)); } } } // This example demonstrates how to get and set properties of the PSD Lnk2 Resource and its liFD data sources for 8 bit per channel. ExampleOfLnk2ResourceSupport("rgb8_2x2_embedded_png.psd", 1, 0x12C, 0x0000079c, Lnk2ResourceSupportCases); // This example demonstrates how to get and set properties of the PSD Lnk3 Resource and its liFD data sources for 32 bit per channel. ExampleOfLnk2ResourceSupport("Layered PSD file smart objects.psd", 2, 0x19504, 0x0001d3e0, LayeredLnk3ResourceSupportCases); // This example demonstrates how to get and set properties of the PSD Lnk2 Resource and its liFD data sources for 16 bit per channel. ExampleOfLnk2ResourceSupport("LayeredSmartObjects16bit.psd", 2, 0x19504, 0x0001d3e0, LayeredLnk2ResourceSupportCases);
string srcFile = "StrokeEffectsSource.psd"; string outputFilePng = "output.png"; using (var psdImage = (PsdImage)Image.Load(srcFile, new PsdLoadOptions() { LoadEffectsResource = true })) { StrokeEffect strokeEffect; IColorFillSettings colorFillSettings; IGradientFillSettings gradientFillSettings; IPatternFillSettings patternFillSettings; // 1. Adds Color fill, at position Inside strokeEffect = psdImage.Layers[1].BlendingOptions.AddStroke(FillType.Color); strokeEffect.Size = 7; strokeEffect.Position = StrokePosition.Inside; colorFillSettings = strokeEffect.FillSettings as IColorFillSettings; colorFillSettings.Color = Color.Green; // 2. Adds Color fill, at position Outside strokeEffect = psdImage.Layers[2].BlendingOptions.AddStroke(FillType.Color); strokeEffect.Size = 7; strokeEffect.Position = StrokePosition.Outside; colorFillSettings = strokeEffect.FillSettings as IColorFillSettings; colorFillSettings.Color = Color.Green; // 3. Adds Color fill, at position Center strokeEffect = psdImage.Layers[3].BlendingOptions.AddStroke(FillType.Color); strokeEffect.Size = 7; strokeEffect.Position = StrokePosition.Center; colorFillSettings = strokeEffect.FillSettings as IColorFillSettings; colorFillSettings.Color = Color.Green; // 4. Adds Gradient fill, at position Inside strokeEffect = psdImage.Layers[4].BlendingOptions.AddStroke(FillType.Gradient); strokeEffect.Size = 5; strokeEffect.Position = StrokePosition.Inside; gradientFillSettings = strokeEffect.FillSettings as IGradientFillSettings; gradientFillSettings.AlignWithLayer = false; gradientFillSettings.Angle = 90; // 5. Adds Gradient fill, at position Outside strokeEffect = psdImage.Layers[5].BlendingOptions.AddStroke(FillType.Gradient); strokeEffect.Size = 5; strokeEffect.Position = StrokePosition.Outside; gradientFillSettings = strokeEffect.FillSettings as IGradientFillSettings; gradientFillSettings.AlignWithLayer = true; gradientFillSettings.Angle = 90; // 6. Adds Gradient fill, at position Center strokeEffect = psdImage.Layers[6].BlendingOptions.AddStroke(FillType.Gradient); strokeEffect.Size = 5; strokeEffect.Position = StrokePosition.Center; gradientFillSettings = strokeEffect.FillSettings as IGradientFillSettings; gradientFillSettings.AlignWithLayer = true; gradientFillSettings.Angle = 0; // 7. Adds Pattern fill, at position Inside strokeEffect = psdImage.Layers[7].BlendingOptions.AddStroke(FillType.Pattern); strokeEffect.Size = 5; strokeEffect.Position = StrokePosition.Inside; patternFillSettings = strokeEffect.FillSettings as IPatternFillSettings; patternFillSettings.Scale = 200; // 8. Adds Pattern fill, at position Outside strokeEffect = psdImage.Layers[8].BlendingOptions.AddStroke(FillType.Pattern); strokeEffect.Size = 10; strokeEffect.Position = StrokePosition.Outside; patternFillSettings = strokeEffect.FillSettings as IPatternFillSettings; patternFillSettings.Scale = 100; // 9. Adds Pattern fill, at position Center strokeEffect = psdImage.Layers[9].BlendingOptions.AddStroke(FillType.Pattern); strokeEffect.Size = 10; strokeEffect.Position = StrokePosition.Center; patternFillSettings = strokeEffect.FillSettings as IPatternFillSettings; patternFillSettings.Scale = 75; psdImage.Save(outputFilePng, new PngOptions()); }
var filesList = new string[] { "BmpExample.bmp", "GifExample.gif", "Jpeg2000Example.jpf", "JpegExample.jpg", "PngExample.png", "TiffExample.tif", }; var expectedExceptionMessage = @"Cannot open an image. The image file format may be not supported at the moment or cannot be opened in such way. If you try to add Layer, please Open File as a Stream and use AddLayer method instead. Check the documentation //docs.aspose.com/display/psdnet/Add+Layer+to+PSD"; foreach (var filePath in filesList) { try { using (var image = Image.Load(filePath)) { } } catch (Exception e) { if (e.InnerException == null || !string.Equals(e.InnerException.Message, expectedExceptionMessage, StringComparison.InvariantCultureIgnoreCase)) { throw e; } } }
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn