彩票走势图

PSD文件处理API-Aspose.PSD v20.7新功能推荐!支持lnk2 / lnk3资源(智能对象层资源)

原创|产品更新|编辑:李显亮|2020-08-03 11:29:14.820|阅读 245 次

概述: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个增强:

  • 支持LnkE资源
  • 支持britResource(亮度/对比度调整层资源)
  • 尝试打开不支持的格式作为图像时更改异常消息

>>你可以点击这里下载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修复

PSDNET-392-支持lnk2 / lnk3资源(智能对象层资源)

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);

PSDNET-673-支持在运行时添加笔画效果

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());
}

PSDNET-629-尝试打开不支持的格式作为图像时,出现“更改异常消息”

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;
         }
     }
 }

还想要更多吗?您可以点击阅读【2020 · Aspose最新资源整合】查找需要的教程资源。如果您有任何疑问或需求,请随时,我们很高兴为您提供查询和咨询
标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@cahobeh.cn


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP