Aspose.PSD for .NET 20.11 - 发行说明
Contents
[
Hide
]
本页面包含Apose.PSD for .NET 20.11的发布说明。
关键 | 摘要 | 类别 |
---|---|---|
PSDNET-713 | Aspose.PSD 无法将 PSD 转换为其他颜色模式/位深度而无需将其另存为文件 | 功能 |
PSDNET-754 | 在 PSD 图像中添加复制智能对象层的功能 | 功能 |
PSDNET-267 | 加载和保存带有图层效果的 PSD 文件时出现异常 | 错误 |
PSDNET-579 | 方法"Image.LoadRawData"引发了空指针异常 | 错误 |
PSDNET-741 | 打开文件时抛出 ImageLoadException 异常 | 错误 |
PSDNET-744 | Aspose.PSD 20.10: 无法加载 PSD | 错误 |
公共 API 更改
添加的 API:
- M:Aspose.PSD.FileFormats.Psd.PsdImage.Convert(Aspose.PSD.ImageOptions.PsdOptions)
- F:Aspose.PSD.FileFormats.Psd.ResourceBlock.ResouceBlockMeSaSignature
- M:Aspose.PSD.FileFormats.Psd.Layers.SmartObjects.SmartObjectLayer.NewSmartObjectViaCopy
- M:Aspose.PSD.FileFormats.Psd.Layers.SmartObjects.SmartObjectLayer.DuplicateLayer
- M:Aspose.PSD.FileFormats.Psd.SmartObjectProvider.NewSmartObjectViaCopy(Aspose.PSD.FileFormats.Psd.Layers.SmartObjects.SmartObjectLayer)
- M:Aspose.PSD.FileFormats.Psd.SmartObjectProvider.ConvertToSmartObject(System.Int32[])
- M:Aspose.PSD.FileFormats.Psd.SmartObjectProvider.ConvertToSmartObject(Aspose.PSD.FileFormats.Psd.Layers.Layer[])
已移除的 API:
- 无
使用示例:
PSDNET-267. 加载和保存带有图层效果的 PSD 文件时出现异常
string dataDir = "PSDNET267_1\\";
string inputFilePath = dataDir + "LayerEffectsTest.psd";
string outputFilePath = dataDir + "LayerEffectsTestOutput.psd";
using (var image = (PsdImage)Image.Load(inputFilePath, new PsdLoadOptions() { LoadEffectsResource = true }))
{
image.Save(outputFilePath, new PsdOptions(image));
}
string dataDir = "PSDNET579_1\\";
string srcFile = dataDir + "CmykWithAlpha_raw.psd";
using (RasterImage image = (RasterImage)Image.Load(srcFile))
{
Rectangle rect = image.Bounds;
RawDataRetriever rawDataRetriever = new RawDataRetriever(rect, image.RawDataSettings);
image.LoadRawData(rect, image.RawDataSettings, rawDataRetriever);
rawDataRetriever.GetData();
}
class RawDataRetriever : Aspose.PSD.IPartialRawDataLoader
{
private readonly byte[] rawData;
private int rawDataIndex;
public RawDataRetriever(Rectangle rectangle, RawDataSettings rawDataSettings)
{
int totalSize = rawDataSettings.LineSize * rectangle.Height;
if (totalSize == 0)
{
totalSize = rectangle.Width * rectangle.Height * 5;
}
this.rawData = new byte[totalSize];
}
public byte[] GetData()
{
return this.rawData;
}
public void Process(Rectangle rectangle, byte[] data, Point start, Point end)
{
Array.Copy(data, 0, this.rawData, this.rawDataIndex, data.Length);
this.rawDataIndex += data.Length;
}
public void Process(Rectangle rectangle, byte[] data, Point start, Point end, LoadOptions loadOptions)
{
throw new NotImplementedException();
}
}
string dataDir = "PSDNET713_1\\";
string outputDir = dataDir + "output\\";
// 这些示例演示了将 PSD 图像格式转换为其他颜色模式/位深度。
ImageConversion(ColorModes.Grayscale, 16, 2);
ImageConversion(ColorModes.Grayscale, 8, 2);
ImageConversion(ColorModes.Grayscale, 8, 1);
ImageConversion(ColorModes.Rgb, 8, 4);
ImageConversion(ColorModes.Rgb, 16, 4);
ImageConversion(ColorModes.Cmyk, 8, 5);
ImageConversion(ColorModes.Cmyk, 16, 5);
void ImageConversion(ColorModes colorMode, short channelBitsCount, short channelsCount)
{
var compression = channelBitsCount > 8 ? CompressionMethod.Raw : CompressionMethod.RLE;
SaveToPsdThenLoadAndSaveToPng(
"SheetColorHighlightExample",
colorMode,
channelBitsCount,
channelsCount,
compression,
1);
SaveToPsdThenLoadAndSaveToPng(
"FillOpacitySample",
colorMode,
channelBitsCount,
channelsCount,
compression,
2);
SaveToPsdThenLoadAndSaveToPng(
"ClippingMaskRegular",
colorMode,
channelBitsCount,
channelsCount,
compression,
3);
}
// 保存为 PSD,然后加载保存为 PNG。
void SaveToPsdThenLoadAndSaveToPng(
string file,
ColorModes colorMode,
short channelBitsCount,
short channelsCount,
CompressionMethod compression,
int layerNumber)
{
string srcFile = dataDir + file + ".psd";
string postfix = colorMode.ToString() + channelBitsCount + "bits" + channelsCount + "channels" +
compression;
string fileName = file + "_" + postfix + ".psd";
string exportPath = outputDir + fileName;
PsdOptions psdOptions = new PsdOptions()
{
ColorMode = colorMode,
ChannelBitsCount = channelBitsCount,
ChannelsCount = channelsCount,
CompressionMethod = compression
};
using (var image = (PsdImage)Image.Load(srcFile))
{
image.Convert(psdOptions);
RasterCachedImage raster = image.Layers.Length > 0 && layerNumber >= 0
? (RasterCachedImage)image.Layers[layerNumber]
: image;
Aspose.PSD.Graphics graphics = new Graphics(raster);
int width = raster.Width;
int height = raster.Height;
Rectangle rect = new Rectangle(
width / 3,
height / 3,
width - (2 * (width / 3)) - 1,
height - (2 * (height / 3)) - 1);
graphics.DrawRectangle(new Aspose.PSD.Pen(Color.DarkGray, 1), rect);
image.Save(exportPath);
}
string pngExportPath = Path.ChangeExtension(exportPath, "png");
using (PsdImage image = (PsdImage)Image.Load(exportPath))
{
image.Save(pngExportPath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
}
}
string dataDir = "PSDNET741_1\\";
string inputFile = dataDir + "input.psd";
string outputFile = dataDir + "output.psd";
using (var psdImage = (PsdImage)Image.Load(inputFile))
{
psdImage.Save(outputFile, new PsdOptions(psdImage));
}
using (var psdImage2 = (PsdImage)Image.Load(outputFile))
{
// 这里不会抛出异常...
}
void AreEqual(object expected, object actual)
{
if (!object.Equals(expected, actual))
{
throw new Exception("Values are not equal.");
}
}
string srcFile = "GST-CHALLAN(2)1..psd";
string output = "output.psd";
using (PsdImage psdImage = (PsdImage)Image.Load(srcFile))
{
AreEqual(ResourceBlock.ResouceBlockMeSaSignature, psdImage.ImageResources[23].Signature);
AreEqual(ResourceBlock.ResouceBlockMeSaSignature, psdImage.ImageResources[24].Signature);
psdImage.Save(output);
}
string dataDir = "PSDNET754_1\\";
string outputDir = dataDir + "output\\";
// 这些示例演示了如何在 PSD 图像中复制智能对象图层。
ExampleOfCopingSmartObjectLayer("r-embedded-psd");
ExampleOfCopingSmartObjectLayer("r-embedded-png");
ExampleOfCopingSmartObjectLayer("r-embedded-transform");
ExampleOfCopingSmartObjectLayer("new_panama-papers-8-trans4");
void ExampleOfCopingSmartObjectLayer(string fileName)
{
int layerNumber = 0; // 要复制的图层编号
string filePath = dataDir + fileName + ".psd";
string outputFilePath = outputDir + fileName + "_copy_" + layerNumber;
string pngOutputPath = outputFilePath + ".png";
string psdOutputPath = outputFilePath + ".psd";
using (PsdImage image = (PsdImage)Image.Load(filePath))
{
var smartObjectLayer = (SmartObjectLayer)image.Layers[layerNumber];
var newLayer = smartObjectLayer.NewSmartObjectViaCopy();
newLayer.IsVisible = false;
AssertIsTrue(object.ReferenceEquals(newLayer, image.Layers[layerNumber + 1]));
AssertIsTrue(object.ReferenceEquals(smartObjectLayer, image.Layers[layerNumber]));
var duplicatedLayer = smartObjectLayer.DuplicateLayer();
duplicatedLayer.DisplayName = smartObjectLayer.DisplayName + "共享图像";
AssertIsTrue(object.ReferenceEquals(newLayer, image.Layers[layerNumber + 2]));
AssertIsTrue(object.ReferenceEquals(duplicatedLayer, image.Layers[layerNumber + 1]));
AssertIsTrue(object.ReferenceEquals(smartObjectLayer, image.Layers[layerNumber]));
using (var innerImage = (RasterImage)smartObjectLayer.LoadContents(null))
{
// 让我们反转嵌入的智能对象图像(对于内部 PSD 图像,我们仅反转其第一层)
InvertImage(innerImage);
// 让我们替换 PSD 图层中的嵌入智能对象图像
smartObjectLayer.ReplaceContents(innerImage);
}
// 复制的图层共享其嵌入的图像,必须显式更新,否则其渲染缓存保持不变。
// 我们更新每个智能对象以确保 NewSmartObjectViaCopy 创建的新图层不与其他图层共享嵌入的图像。
image.SmartObjectProvider.UpdateAllModifiedContent();
image.Save(pngOutputPath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
image.Save(psdOutputPath, new PsdOptions(image));
}
}
// 反转包括 PSD 图像在内的光栅图像。
void InvertImage(RasterImage innerImage)
{
var innerPsdImage = innerImage as PsdImage;
if (innerPsdImage != null)
{
InvertRasterImage(innerPsdImage.Layers[0]);
}
else
{
InvertRasterImage(innerImage);
}
}
// 反转光栅图像。
void InvertRasterImage(RasterImage innerImage)
{
var pixels = innerImage.LoadArgb32Pixels(innerImage.Bounds);
for (int i = 0; i < pixels.Length; i++)
{
var pixel = pixels[i];
var alpha = (int)(pixel & 0xff000000);
pixels[i] = (~(pixel & 0x00ffffff)) | alpha;
}
innerImage.SaveArgb32Pixels(innerImage.Bounds, pixels);
}
void AssertIsTrue(bool condition)
{
if (!condition)
{
throw new FormatException(string.Format("Expected true"));
}
}