Aspose.PSD for .NET 20.7 - 发行说明

关键 摘要 类别
PSDNET-673 支持 LnkE 资源 功能
PSDNET-392 支持 britResource(亮度/对比度调整图层的资源) 功能
PSDNET-629 试图打开不支持的格式作为图像时更改异常消息 增强
PSDNET-594 无法保存 LayerMask 错误
PSDNET-597 在创建新的图层组后保存 PSD 文件会在文件打开时收到 Photoshop 警告 错误
PSDNET-618 剪裁蒙版未应用于文件夹 错误
PSDNET-625 使用 Aspose.PSD for .NET 无法打开文件 错误
PSDNET-650 将 PSD 转换为 PDF 时出现图像保存失败的异常 错误
PSDNET-655 在 PSD 图像中进行 rop 操作使剪切路径无效 错误
PSDNET-662 尝试保存具有阴影效果的特定 PSD 文件时出现 NullReference 异常 错误
PSDNET-666 Aspose.PSD 在 Image.CanLoad(pdfStream) 上返回 true 错误
PSDNET-676 生成的 PNG 中图层无法呈现 错误
PSDNET-677 访问 TextData 时引发异常 错误
PSDNET-679 保存 PSD 时出现 ImageSaveException 错误

公共 API 更改

已添加的 API:

  • M:Aspose.PSD.FileFormats.Psd.Layers.LayerEffects.BlendingOptions.AddStroke(Aspose.PSD.FileFormats.Psd.Layers.FillSettings.FillType)
  • P:Aspose.PSD.FileFormats.Psd.Layers.LayerEffects.StrokeEffect.Overprint
  • P:Aspose.PSD.FileFormats.Psd.Layers.LayerEffects.StrokeEffect.Position
  • P:Aspose.PSD.FileFormats.Psd.Layers.LayerEffects.StrokeEffect.Size
  • T:Aspose.PSD.FileFormats.Psd.Layers.LayerEffects.StrokePosition
  • F:Aspose.PSD.FileFormats.Psd.Layers.LayerEffects.StrokePosition.Inside
  • F:Aspose.PSD.FileFormats.Psd.Layers.LayerEffects.StrokePosition.Center
  • F:Aspose.PSD.FileFormats.Psd.Layers.LayerEffects.StrokePosition.Outside
  • P:Aspose.PSD.FileFormats.Psd.Layers.LayerResources.LiFdDataSource.Data
  • P:Aspose.PSD.FileFormats.Psd.Layers.LayerResources.Lnk2Resource.Item(System.Int32)
  • M:Aspose.PSD.FileFormats.Psd.Layers.LayerResources.Lnk2Resource.#ctor
  • T:Aspose.PSD.FileFormats.Psd.Layers.LayerResources.Lnk3Resource
  • P:Aspose.PSD.FileFormats.Psd.Layers.LayerResources.Lnk3Resource.Key
  • F:Aspose.PSD.FileFormats.Psd.Layers.LayerResources.Lnk3Resource.TypeToolKey
  • M:Aspose.PSD.FileFormats.Psd.Layers.LayerResources.Lnk3Resource.#ctor
  • T:Aspose.PSD.FileFormats.Psd.Resources.WorkingPathResource
  • M:Aspose.PSD.FileFormats.Psd.Resources.WorkingPathResource.#ctor(System.Byte[])
  • P:Aspose.PSD.FileFormats.Psd.Resources.WorkingPathResource.DataSize
  • P:Aspose.PSD.FileFormats.Psd.Resources.WorkingPathResource.MinimalVersion
  • P:Aspose.PSD.FileFormats.Psd.Resources.WorkingPathResource.Paths
  • P:Aspose.PSD.FileFormats.Psd.Resources.WorkingPathResource.Version
  • P:Aspose.PSD.FileFormats.Psd.Resources.WorkingPathResource.IsDisabled
  • P:Aspose.PSD.FileFormats.Psd.Resources.WorkingPathResource.IsNotLinked
  • P:Aspose.PSD.FileFormats.Psd.Resources.WorkingPathResource.IsInverted
  • T:Aspose.PSD.FileFormats.Psd.Layers.LayerResources.VectorPaths.IVectorPathData
  • P:Aspose.PSD.FileFormats.Psd.Layers.LayerResources.VectorPaths.IVectorPathData.Paths
  • P:Aspose.PSD.FileFormats.Psd.Layers.LayerResources.VectorPaths.IVectorPathData.Version
  • P:Aspose.PSD.FileFormats.Psd.Layers.LayerResources.VectorPaths.IVectorPathData.IsDisabled
  • P:Aspose.PSD.FileFormats.Psd.Layers.LayerResources.VectorPaths.IVectorPathData.IsNotLinked
  • P:Aspose.PSD.FileFormats.Psd.Layers.LayerResources.VectorPaths.IVectorPathData.IsInverted

已移除的 API:

  • M:Aspose.PSD.FileFormats.Psd.PsdImage.AddExposureLayer(System.Single,System.Single,System.Single)

使用示例:

PSDNET-606. 支持 LnkE 资源

void AssertAreEqual(object expected, object actual)
 {
     if (!object.Equals(actual, expected))
     {
         throw new FormatException(string.Format("实际值 {0} 与预期值 {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\";

 // 将 PSD 文件中的智能对象数据保存到文件中。
 void SaveSmartObjectData(string prefix, string fileName, byte[] data)
 {
     var filePath = basePath + prefix + "_"  + fileName;

     using (var container = FileStreamContainer.CreateFileStream(filePath, false))
     {
         container.Write(data);
     }
 }

 // 为 PSD 文件中的智能对象加载新数据。
 byte[] LoadNewData(string fileName)
 {
     using (var container = FileStreamContainer.OpenFileStream(basePath + fileName))
     {
         return container.ToBytes();
     }
 }

 // 获取并设置 PSD 文件中的 Lnk2 / Lnk3 资源及其 liFD 数据源的属性
 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));
         }
     }
 }

 // 此示例演示了如何获取并设置 PSD Lnk2 资源及其 liFD 数据源的属性(每通道 8 位)。
 ExampleOfLnk2ResourceSupport("rgb8_2x2_embedded_png.psd", 1, 0x12C, 0x0000079c, Lnk2ResourceSupportCases);

 // 此示例演示了如何获取并设置 PSD Lnk3 资源及其 liFD 数据源的属性(每通道 32 位)。
 ExampleOfLnk2ResourceSupport("Layered PSD file smart objects.psd", 2, 0x19504, 0x0001d3e0, LayeredLnk3ResourceSupportCases);

 // 此示例演示了如何获取并设置 PSD Lnk2 资源及其 liFD 数据源的属性(每通道 16 位)。
 ExampleOfLnk2ResourceSupport("LayeredSmartObjects16bit.psd", 2, 0x19504, 0x0001d3e0, LayeredLnk2ResourceSupportCases);

PSDNET-201. 文档转换进度支持

string sourceFilePath = "Apple.psd";
Stream outputStream = new MemoryStream();
ProgressEventHandler localProgressEventHandler = delegate(ProgressEventHandlerInfo progressInfo)
{
      string message = string.Format(
           "{0} {1}: {2} of {3}",
           progressInfo.Description,
           progressInfo.EventType,
           progressInfo.Value,
           progressInfo.MaxValue);
      Console.WriteLine(message);
};
Console.WriteLine("---------- 加载 Apple.psd ----------");
var loadOptions = new PsdLoadOptions() { ProgressEventHandler = localProgressEventHandler };
using (PsdImage image = (PsdImage)Image.Load(sourceFilePath, loadOptions))
{
      Console.WriteLine("---------- 将 Apple.psd 保存为 PNG 格式 ----------");
      image.Save(
           outputStream,
           new PngOptions()
           {
                 ColorType = PngColorType.Truecolor, ProgressEventHandler = localProgressEventHandler
           });
      Console.WriteLine("---------- 将 Apple.psd 保存为 PSD 格式 ----------");
      image.Save(
           outputStream,
           new PsdOptions()
           {
                 ColorMode = ColorModes.Rgb,
                 ChannelsCount = 4,
                 ProgressEventHandler = localProgressEventHandler
           });
}

PSDNET-386. 支持 britResource(亮度/对比度调整图层的资源)

 /* 此示例演示如何以编程方式更改 PSD 图像的亮度/对比度图层资源 - BritResource

   这是 Aspose.PSD 的低级 API。您可以通过其 API 使用 Brightness/Contrast Layer,这会更容易, 

   但直接编辑 Photoshop 资源可以更好地控制 PSD 文件内容。  */

string path = @"BrightnessContrastPS6.psd";
string outputPath = @"BrightnessContrastPS6_output.psd";
using (PsdImage im = (PsdImage)Image.Load(path))

{
    foreach (var layer in im.Layers)
    {
        if (layer is BrightnessContrastLayer)
        {
            foreach (var layerResource in layer.Resources)
            {
                if (layerResource is BritResource)
                {
                    var resource = (BritResource)layerResource;
                    isRequiredResourceFound = true;
                    if (resource.Brightness != -40 ||
                        resource.Contrast != 10 ||
                        resource.LabColor != false ||
                        resource.MeanValueForBrightnessAndContrast != 127)
                    {
                        throw new Exception("BritResource was read wrong");
                    }

                    // Test editing and saving
                    resource.Brightness = 25;
                    resource.Contrast = -14;
                    resource.LabColor = true;
                    resource.MeanValueForBrightnessAndContrast = 200;
                    im.Save(outputPath, new PsdOptions());
                    break;
                }
            }
        }
    }
}

PSDNET-596. 具有非 PassThrough 混合模式的图层组不会呈现

 string sourceFilePath = "MaskTestNormalBlendMaskOnGroup.psd";
string outputFilePath = "MaskTestNormalBlendMaskOnGroup.png";
using (var input = (PsdImage)Image.Load(sourceFilePath))

{
    input.Save(outputFilePath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
}

PSDNET-610. 尝试将特定 Psd 文件转换为图像时出现 NullReference 异常

 using (var psdImage = (PsdImage)Image.Load("Certificate.psd"))

{
    psdImage.Save("output.png", new PngOptions());
}

PSDNET-636. 如果调整图层中有边界为空的蒙版,则调整 PSD 文件大小会出现错误

int scale = 2;
string[] names = {
                     "OneRegularAndOneAdjustmentWithVectorAndLayerMask",
                     "LevelsLayerWithLayerMaskRgb",
                     "LevelsLayerWithLayerMaskCmyk",
                 };
for (int i = 0; i < names.Length; i++)
{
    string sourceFilePath = names[i] + ".psd";
    string outputFilePath = "output_" + sourceFilePath;
    string outputPngFilePath = "output_" + names[i] + ".png";
    var psdLoadOptions = new PsdLoadOptions() { LoadEffectsResource = true };
    using (PsdImage image = (PsdImage)Image.Load(sourceFilePath, psdLoadOptions))
    {
        image.Resize(image.Width * scale, image.Height * scale);
        image.Save(outputFilePath, new PsdOptions());
        image.Save(outputPngFilePath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
    }
}

PSDNET-611. 打开特定 Psd 文件时出现 OverflowException

 using (var psdImage = (PsdImage)Image.Load("CT_SkillTest_v1.psd"))
{
    psdImage.Save("output.psd");
}
// 载入并保存而不引发异常。

PSDNET-565. 具有 RGB 模式 16 位/通道的 Psd 图像仅在预览时更新图层

string sourceFilePath = @"in.psd";
string outputFilePath = @"output.psd";
Psd