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

关键 摘要 类别
PSDNET-1237 创建内部 LayerStyleFX 模型,用于包含效果和相关数据,以在效果资源 Lfx2、lmfx 和 mlst 中使用单个模型 增强功能
PSDNET-1227 添加读取和写入 ‘Lefx’ 结构的功能,其中包含时间线模型中图层状态的效果信息 特性
PSDNET-1230 将时间线图层状态应用于 PsdImage 中的图层 特性
PSDNET-1072 在导出至 8 位时,将 PSD 文件(RGB/16 位)上的不正确透明度保存 错误
PSDNET-1140 打开 PSB 文档时加载全局图层资源步骤中出现异常 错误
PSDNET-1266 在处理特定文件时存在内存泄漏 错误

公共 API 更改

已添加的 API:

  • P:Aspose.PSD.FileFormats.Psd.Layers.Animation.LayerState.PositionOffset
  • P:Aspose.PSD.FileFormats.Psd.Layers.Animation.LayerState.StateEffects
  • T:Aspose.PSD.FileFormats.Psd.Layers.Animation.LayerStateEffects
  • P:Aspose.PSD.FileFormats.Psd.Layers.Animation.LayerStateEffects.IsVisible
  • P:Aspose.PSD.FileFormats.Psd.Layers.Animation.LayerStateEffects.Effects
  • M:Aspose.PSD.FileFormats.Psd.Layers.Animation.LayerStateEffects.AddDropShadow
  • M:Aspose.PSD.FileFormats.Psd.Layers.Animation.LayerStateEffects.AddInnerShadow
  • M:Aspose.PSD.FileFormats.Psd.Layers.Animation.LayerStateEffects.AddOuterGlow
  • M:Aspose.PSD.FileFormats.Psd.Layers.Animation.LayerStateEffects.AddStroke(Aspose.PSD.FileFormats.Psd.Layers.FillSettings.FillType)
  • M:Aspose.PSD.FileFormats.Psd.Layers.Animation.LayerStateEffects.AddColorOverlay
  • M:Aspose.PSD.FileFormats.Psd.Layers.Animation.LayerStateEffects.AddGradientOverlay
  • M:Aspose.PSD.FileFormats.Psd.Layers.Animation.LayerStateEffects.AddPatternOverlay
  • M:Aspose.PSD.FileFormats.Psd.Layers.Animation.LayerStateEffects.ClearLayerStyle
  • M:Aspose.PSD.FileFormats.Psd.Layers.Animation.LayerStateEffects.RemoveEffectAt(System.Int32)

已移除的 API:

  • P:Aspose.PSD.FileFormats.Psd.Layers.Animation.LayerState.Offset

使用示例:

PSDNET-1072.在导出至 8 位时,将 PSD 文件(RGB/16 位)上的不正确透明度保存

string inputPsdFile    = "8bitWithTransparency.psd";
string outputPsdFile   = "16bitWithTransparency.psd";
string outputImageFile = "OutputWithTransparency.png";

using (var img = Image.Load(inputPsdFile))
{
    // 16 位保存选项
    PsdOptions p16 = new PsdOptions() { ChannelBitsCount = 16, ColorMode = ColorModes.Rgb };

    img.Save(outputPsdFile, p16);
}
using (var img = Image.Load(outputPsdFile))
{
    // 使用 16 位颜色保存图片
    img.Save(outputImageFile, new PngOptions() { ColorType = Aspose.PSD.FileFormats.Png.PngColorType.TruecolorWithAlpha });
}

PSDNET-1140.在打开 PSB 文档时加载全局图层资源步骤中出现异常

string sourcePsdFile = "input.psb";
string outputImageFile = "output.png";

using (var image = (PsdImage)Image.Load(sourcePsdFile))
{
    // 这里不应该出现异常。
    image.Save(outputImageFile, new PngOptions() { ColorType = PngColorType.GrayscaleWithAlpha });
}

PSDNET-1227.添加读取和写入 ‘Lefx’ 结构的功能,其中包含时间线模型中图层状态的效果信息

string sourceFile = "4_animated.psd";
string outputFile = "output.psd";

using (var psdImage = (PsdImage)Image.Load(sourceFile))
{
    TimeLine timeLine = TimeLine.InitializeFrom(psdImage);
    int[] layerIds = timeLine.LayerIds;

    var layerStateEffects11 = timeLine.Frames[1].LayerStates[layerIds[1]].StateEffects;

    layerStateEffects11.AddDropShadow();
    layerStateEffects11.AddGradientOverlay();

    var layerStateEffects21 = timeLine.Frames[2].LayerStates[layerIds[1]].StateEffects;
    layerStateEffects21.AddStroke(FillType.Color);
    layerStateEffects21.IsVisible = false;

    timeLine.ApplyTo(psdImage);

    psdImage.Save(outputFile);
}

PSDNET-1230.将时间线图层状态应用于 PsdImage 中的图层

string sourceFile = "3_animated.psd";
string outputPsd = "output.psd";
string outputPng = "output.png";

using (var psdImage = (PsdImage)Image.Load(sourceFile, new PsdLoadOptions() { LoadEffectsResource = true }))
{
    TimeLine timeLine = TimeLine.InitializeFrom(psdImage);
    var layerIds = timeLine.LayerIds;

    var layerState11 = timeLine.Frames[1].LayerStates[layerIds[1]];

    timeLine.Frames[1].LayerStates[layerIds[1]].StateEffects.AddPatternOverlay();
    layerState11.BlendMode = BlendMode.Multiply;

    // 将活动帧从 0 更改为 1 以启用将 LayerState 应用于 Layer
    timeLine.ActiveFrame = 1;

    // 将更改应用于 PsdImage
    timeLine.ApplyTo(psdImage);

    psdImage.Save(outputPsd);
    psdImage.Save(outputPng, new PngOptions());
}

PSDNET-1266.处理特定文件时存在内存泄漏

string[] filesToLoad = new string[] { "testPsd0.psd", "testPsd1.psd", "testPsd2.psd" };
int inputNumber = GC.MaxGeneration;

#if NETCOREAPP
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
#endif
GC.Collect(inputNumber, GCCollectionMode.Forced);
GC.WaitForFullGCComplete();

double memCount = (double)Process.GetCurrentProcess().PrivateMemorySize64 / 1024 / 1024;
Console.WriteLine("测试前使用的总字节: {0:N2} MiB", memCount);

double max = memCount;

for (int i = 0; i < 50; i++)
{
    int fileIndex = i % inputNumber;
    string sourceFile = Path.Combine(baseFolder, filesToLoad[fileIndex]);

    // 检查打开和保存
    using (MemoryStream outputStream = new MemoryStream())
    {
        using (PsdImage psd = (PsdImage)Image.Load(sourceFile, new PsdLoadOptions { LoadEffectsResource = true }))
        {
            psd.Save(outputStream, new JpegOptions() { Quality = 100 });
        }
    }

#if NETCOREAPP
    GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
#endif
    GC.Collect(inputNumber, GCCollectionMode.Forced);
    GC.WaitForFullGCComplete();

    memCount = (double)Process.GetCurrentProcess().PrivateMemorySize64 / 1024 / 1024;
    max = Math.Max(max, memCount);
}

memCount = (double)Process.GetCurrentProcess().PrivateMemorySize64 / 1024 / 1024;
Console.WriteLine("测试后使用的总字节: {0:N2} MiB", memCount);
Assert.IsTrue(Math.Abs(memCount - max) < 20, "发现基本功能中的内存泄漏!");