如何使用 Aspose.PSD 为 .NET 添加框架到 PSD 动画时间表

如何使用 Aspose.PSD 为 .NET 添加框架到 PSD 动画时间表

将框架添加到动画的PSD程序为自动化创意工作流、扩展广告或调整动作包装至关重要。

现实世界问题

创意团队和营销人员经常需要在现有 PSD 时间表中添加输入/输出或效果框,而无需在 Photoshop 中手动编辑。

解决方案概述

使用 Aspose.PSD for .NET,您可以在动画的时间线中插入新的框架对象,甚至可以将现有框作为起点克隆,从而确保视觉一致性。

原則

  • Visual Studio 2019 或以后
  • .NET 6.0 或更高版本(或 .Net Framework 4.6.2+)
  • Aspose.PSD 为 .NET 从 NuGet
  • 动画的PSD/PSB文件与时间线框
PM> Install-Package Aspose.PSD

步骤实施

步骤1:在动画时间表中添加一个新的框架

using Aspose.PSD;
using Aspose.PSD.FileFormats.Psd;
using Aspose.PSD.FileFormats.Psd.Layers;
using Aspose.PSD.FileFormats.Psd.Resources;
using Aspose.PSD.ImageOptions;

string inputFile = "./input/animation.psd";
string outputFile = "./output/animation_with_new_frame.psd";

var loadOptions = new PsdLoadOptions() { LoadEffectsResource = true };

using (PsdImage psdImage = (PsdImage)Image.Load(inputFile, loadOptions))
{
    var timeline = psdImage.Timeline;

    // Clone the last frame as a template for the new frame
    var frames = new List<Frame>(timeline.Frames);
    Frame newFrame = frames[frames.Count - 1].Clone() as Frame;

    // Optional: Adjust properties of the new frame
    newFrame.Delay = 20; // Set delay
    // Modify layer states as needed, e.g.:
    // newFrame.LayerStates[1].Opacity = 80;

    // Add the new frame to the timeline
    frames.Add(newFrame);
    timeline.Frames = frames.ToArray();

    // Save the updated PSD
    psdImage.Save(outputFile);
}

(所有基于官方 Aspose.PSD Animation Maker API 参考和验证编辑的代码)

使用案例和应用程序

  • 添加输入/输出或效果框到营销广告
  • 在动画创意资产中插入突出/过渡框
  • 扩展动画时间为 A/B 测试程序

共同挑战与解决方案

Wrong frame count 添加后: 始终更新 Frames 改變後發動。

** 不需要的视觉复制:** 在添加之前调整克隆框属性(延迟、层变化等)。

最佳实践

  • 克隆框 维持层结构
  • 文档框改变可再生性
  • 修改后预览动画

FAQ

Q:我可以插入白色或自定义框吗?**答:是的,在添加之前创建一个新的框架并设置其 LayerStates。

**Q:将添加框架出口到GIF吗?**答:是的,时间表编辑在所有出口中都反映。

结论

Aspose.PSD for .NET 允许您自动扩展和编辑动画 PSD 的时间线,简化旗帜创建和创意活动。 Aspose.PSD 为 .NET API 参考 .

 中文