Aspose.PSD for .NET 23.7 - 发布说明
Contents
[
Hide
]
本页面包含了 Aspose.PSD for .NET 23.7 的发布说明
关键字 | 摘要 | 类别 |
---|---|---|
PSDNET-802 | 添加导出 PSD 文件每一图层至动画 Gif 文件的功能 | 功能 |
PSDNET-1441 | 为形状图层分配来自 vscg 资源的填充属性 | 功能 |
PSDNET-1534 | 添加新的扭曲类型 (arc & arch) | 功能 |
PSDNET-1543 | 更改保存 PSD 文件应用为 Aspose.PSD,如果属性 UpdateMetadata 设置为 true | 功能 |
PSDNET-1567 | 增加扭曲图像的计算区域 | 功能 |
PSDNET-1471 | 黑白调整图层处理半透明度错误 | 缺陷 |
PSDNET-1505 | SmartObject ReplaceContents(当 AllowWarpRepaint 选项激活时)在计算 2 分钟后中断 | 缺陷 |
PSDNET-1585 | 添加获取真正的图层组左侧和顶部位置的功能 | 缺陷 |
PSDNET-1589 | 当 psd 文件中具有 VogkResource 的结构时,调整图层的大小工作不正常 | 缺陷 |
PSDNET-1608 | TextBound 不符合预期工作 | 缺陷 |
PSDNET-1612 | 将默认构造函数创建的图层添加到 PSD 图像时,不会将默认资源添加到图层 | 缺陷 |
PSDNET-1623 | 导出为动画 GIF 时,忽略 Timeline.LoopesCount | 缺陷 |
公共 API 更改
新增 API:
- P:Aspose.PSD.ImageOptions.PsdOptions.UpdateMetadata
- F:Aspose.PSD.FileFormats.Ai.AiFormatVersion.Pdf16
- F:Aspose.PSD.FileFormats.Ai.AiFormatVersion.Pdf17
- P:Aspose.PSD.Xmp.Schemas.XmpBaseSchema.XmpBasicPackage.Item(System.String)
- M:Aspose.PSD.Xmp.Schemas.XmpBaseSchema.XmpBasicPackage.SetValue(System.String,Aspose.PSD.Xmp.IXmlValue)
- M:Aspose.PSD.Xmp.Schemas.XmpBaseSchema.XmpBasicPackage.ContainsKey(System.String)
- P:Aspose.PSD.FileFormats.Psd.Layers.ShapeLayer.Fill
移除 API:
- P:Aspose.PSD.FileFormats.Psd.Layers.LayerResources.VectorPath.FillColor
用法示例:
PSDNET-802. 添加导出 PSD 文件每一图层至动画 Gif 文件的功能
string src = "EachLayerIsFrame.psd";
string outputGif = "out_EachLayerIsFrame.gif";
string outputPsd = "out_EachLayerIsFrame.psd";
using (var psdImage = (PsdImage)Image.Load(src))
{
// 为每个图层创建帧。
int framesCount = psdImage.Layers.Length;
var timeline = psdImage.Timeline;
Frame[] frames = new Frame[framesCount];
for (int i = 0; i < framesCount; i++)
{
frames[i] = new Frame();
LayerState[] layerStates = new LayerState[framesCount];
for (int j = 0; j < framesCount; j++)
{
layerStates[j] = new LayerState();
layerStates[j].Enabled = i == j;
}
frames[i].LayerStates = layerStates;
}
timeline.Frames = frames;
// 更新当前状态
Layer[] layers = psdImage.Layers;
LayerState[] states = timeline.Frames[timeline.ActiveFrameIndex].LayerStates;
for (int i = 0; i < framesCount; i++)
{
layers[i].IsVisible = states[i].Enabled;
}
timeline.Save(outputGif, new GifOptions());
psdImage.Save(outputPsd);
}
PSDNET-1441. 为形状图层分配来自 vscg 资源的填充属性
string srcFile = "ShapeInternalSolid.psd";
string outFile = "ShapeInternalSolid.psd.out.psd";
using (PsdImage image = (PsdImage)Image.Load(
srcFile,
new PsdLoadOptions { LoadEffectsResource = true }))
{
ShapeLayer shapeLayer = (ShapeLayer)image.Layers[1];
ColorFillSettings fillSettings = (ColorFillSettings)shapeLayer.Fill;
fillSettings.Color = Color.Red;
shapeLayer.Update();
image.Save(outFile);
}
// 检查保存的更改
using (PsdImage image = (PsdImage)Image.Load(
outFile,
new PsdLoadOptions { LoadEffectsResource = true }))
{
ShapeLayer shapeLayer = (ShapeLayer)image.Layers[1];
ColorFillSettings fillSettings = (ColorFillSettings)shapeLayer.Fill;
AssertAreEqual(Color.Red, fillSettings.Color);
image.Save(outFile);
}
void AssertAreEqual(object expected, object actual, string message = null)
{
if (!object.Equals(expected, actual))
{
throw new Exception(message ?? "对象不相等。");
}
}
PSDNET-1471. 黑白调整图层处理半透明度错误
string srcFile = "frog_nosymb.psd";
string outFile = "frog_nosymb.psd.out.psd";
using (PsdImage psdImage = (PsdImage)Image.Load(srcFile))
{
psdImage.AddBlackWhiteAdjustmentLayer();
psdImage.Save(outFile);
}
// 检查保存的更改
using (PsdImage image = (PsdImage)Image.Load(
outFile,
new PsdLoadOptions { LoadEffectsResource = true }))
{
AssertAreEqual(2, image.Layers.Length);
BlackWhiteAdjustmentLayer blackWhiteAdjustmentLayer = (BlackWhiteAdjustmentLayer)image.Layers[1];
if (blackWhiteAdjustmentLayer == null)
{
throw new Exception("第 2 图层应为 BlackWhiteAdjustmentLayer");
}
image.Save(outFile);
}
void AssertAreEqual(object expected, object actual, string message = null)
{
if (!object.Equals(expected, actual))
{
throw new Exception(message ?? "对象不相等。");
}
}
PSDNET-1505. SmartObject ReplaceContents(当 AllowWarpRepaint 选项激活时)在计算 2 分钟后中断
string sourceFile = "mug 4.psd";
string changeFile = "artwork for replace.png";
string outputFile = "export.png";
int newHeight = 300;
using (var psdImage = (PsdImage)Image.Load(sourceFile, new PsdLoadOptions() { AllowWarpRepaint = true, LoadEffectsResource = true }))
{
SmartObjectLayer smartObjectLayer = (SmartObjectLayer)psdImage.Layers[3];
var scale = (double)newHeight / smartObjectLayer.Height;
var newWidth = (int)Math.Round(smartObjectLayer.Width * scale);
PsdImage innerImage = new PsdImage(newWidth, newHeight);
innerImage.SetResolution(72, 72);
Stream innerStream = new FileStream(changeFile, FileMode.Open);
Layer layer = new Layer(innerStream) { HorizontalResolution = 72, VerticalResolution = 72 };
try
{
innerImage.AddLayer(layer);
smartObjectLayer.ReplaceContents(innerImage);
smartObjectLayer.UpdateModifiedContent();
psdImage.Save(outputFile, new PngOptions
{
ColorType = PngColorType.TruecolorWithAlpha
});
}
finally
{
innerImage.Dispose();
innerStream.Dispose();
layer.Dispose();
}
}
PSDNET-1534. 添加新的扭曲类型 (arc & arch)
string sourceArcFile = "arc_warp.psd";
string outputArcFile = "arc_export.png";
string sourceArchFile = "arch_warp.psd";
string outputArchFile = "arch_export.png";
using (var psdImage = (PsdImage)Image.Load(sourceArcFile, new PsdLoadOptions() { AllowWarpRepaint = true, LoadEffectsResource = true }))
{
psdImage.Save(outputArcFile, new PngOptions
{
ColorType = PngColorType.TruecolorWithAlpha
});
}
using (var psdImage = (PsdImage)Image.Load(sourceArchFile, new PsdLoadOptions() { AllowWarpRepaint = true, LoadEffectsResource = true }))
{
psdImage.Save(outputArchFile, new PngOptions
{
ColorType = PngColorType.TruecolorWithAlpha
});
}
PSDNET-1543. 更改保存 PSD 文件应用为 Aspose.PSD,如果属性 UpdateMetadata 设置为 true
string path = "output.psd";
using (var image = new PsdImage(100, 100))
{
// 如果要更改创建工具,请确保将 "UpdateMetadata" 属性设置为 true。 默认情况下设置为 true。
var psdOptions = new PsdOptions();
psdOptions.UpdateMetadata = true;
// 保存图像。
image.Save(path, psdOptions);
// 在代码中检查创建工具。
var xmpData = image.XmpData;
var basicPackage = image.XmpData.GetPackage(Namespaces.XmpBasic);
// 这里将更新创建工具信息。
var currentCreatorTool = (string)basicPackage[":CreatorTool"];
}
PSDNET-1567. 增加扭曲图像的计算区域
string sourceFile = "mug4_warp.psd";
string outputFile = "mug4_export.png";
using (var psdImage = (PsdImage)Image.Load(sourceFile, new PsdLoadOptions() { AllowWarpRepaint = true, LoadEffectsResource = true }))
{
psdImage.Save(outputFile, new PngOptions
{
ColorType = PngColorType.TruecolorWithAlpha
});
}
PSDNET-1585. 添加获取真正的图层组左侧和顶部位置的功能
string sourceFile = "layerGroupFigures.psd";
void AssertAreEqual(object expected, object actual)
{
if (!object.Equals(expected, actual))
{
throw new Exception("对象不相等。");
}
}
using (var image = (PsdImage)Image.Load(sourceFile))
{
var layers = image.Layers;
for (int i = 0; i < layers.Length; i++)
{
var layer = layers[i];
if (layer is LayerGroup)
{
// 获取 LayerGroup。
var group = (LayerGroup)layer;
var expectedLeft = int.MaxValue;
var expectedTop = int.MaxValue;
var expectedRight = 0;
var expectedBottom = 0;
// 计算真正的左侧、顶部、右侧和底部位置。
foreach (var innerLayer in group.Layers)
{
if (innerLayer is AdjustmentLayer || innerLayer.Bounds.IsEmpty)
{
continue;
}
expectedLeft = Math.Min(expectedLeft, innerLayer.Left);
expectedTop = Math.Min(expectedTop, innerLayer.Top);
expectedRight = Math.Max((expectedLeft + group.Width), (innerLayer.Left + innerLayer.Width));
expectedBottom = Math.Max((expectedTop + group.Height), (innerLayer.Top + innerLayer.Height));
}
// LayerGroup 的左、顶、右、底位置现在已正确计算。
AssertAreEqual(group.Left, expectedLeft);
AssertAreEqual(group.Top, expectedTop);
AssertAreEqual(group.Right, expectedRight);
AssertAreEqual(group.Bottom, expectedBottom);
}
}
}
PSDNET-1589. 当 psd 文件中具有 VogkResource 的结构时,调整图层的大小工作不正常
string[] sourceFiles = new string[]
{
"PointsVectorOrigin.psd",
"TopVogkResStruct.psd"
};
foreach (string sourceFile in sourceFiles)
{
using (PsdImage image = (PsdImage)Image.Load(sourceFile))
{
Layer layer = image.Layers[0];
layer.Resize(50, 50);
AssertAreEqual(layer.Height, 50);
AssertAreEqual(layer.Width, 50);
}
}
void AssertAreEqual(object expected, object actual, string message = null)
{
if (!object.Equals(expected, actual))
{
throw new Exception(message ?? "对象不相等。");
}
}
PSDNET-1608. TextBound 不符合预期工作
string sourceFile = "input_Test_forTicket.psd";
string outFile = "out_1608.psd";
Size newTextBox = new Size(-1, -1);
using (PsdImage psdImage = (PsdImage)Aspose.PSD.Image.Load(sourceFile))
{
//步骤:替换文本
TextLayer textLayer = (TextLayer)psdImage.Layers[3];
textLayer.TextData.Items[0].Text = "Text test replaced";
//步骤:更新 TextBoundBox
textLayer.TextData.UpdateLayerData();
newTextBox = new Size((int)Math.Ceiling(textLayer.TextBoundBox.Width), textLayer.Height);
textLayer.TextBoundBox = new Aspose.PSD.RectangleF(PointF.Empty, newTextBox);
textLayer.TextData.UpdateLayerData();
psdImage.Save(outFile);
}
// 检查更改
using (var psdImage = (PsdImage)Image.Load(outFile))
{
Txt2Resource txt2Resource = (Txt2Resource)psdImage.GlobalLayerResources[1];
string textData = Encoding.GetEncoding("Windows-1251").GetString(txt2Resource.Data);
string search = "<< /0 << /1 << /0 ["; //用于查找此文件中的 textBox 值的特定字符集。
int startIndex = textData.IndexOf(search) + search.Length;
int endIndex = textData.IndexOf("]", startIndex);
string boxItems = textData.Substring(startIndex, endIndex - startIndex);
string height = newTextBox.Height.ToString("0.0####").Replace(",", ".");
string width = newTextBox.Width.ToString("0.0####").Replace(",", ".");
if (!boxItems.Contains(height) || !boxItems.Contains(width))
{
throw new Exception("TextBox 未更新。");
}
}
PSDNET-1612. 将默认构造函数创建的图层添加到 PSD 图像时,不会将默认资源添加到图层
string output = "newLayer.psd";
using (var psdImage = new PsdImage(500, 500))
{
var layer = new Layer();
psdImage.AddLayer(layer);
LyidResource lyidResource = (LyidResource)FindResource(LyidResource.TypeToolKey, layer.Resources);
int layerId = lyidResource.Value; //会出现 NullReferenceException
psdImage.Save(output);
}
LayerResource FindResource(int resType, LayerResource[] resources)
{
if (resources != null)
{
foreach (var layerResource in resources)
{
if (layerResource.Key == resType)
{
return layerResource;
}
}
}
return null;
}
PSDNET-1623. 导出为动画 GIF 时,忽略 Timeline.LoopesCount
string sourceFile = "4_animated.psd";
string outputGif = "out_4_animated.psd.gif";
using (var psdImage = (PsdImage)Image.Load(sourceFile, new PsdLoadOptions() { LoadEffectsResource = true }))
{
psdImage.Timeline.Save(outputGif, new GifOptions());
}