Aspose.PSD for .NET 24.5 (DLLs package) facilitates developers with an upgraded feature set and simplified integration for processing PSD and AI files within their C# and VB.NET apps on a platform of their choice.
This C# PSD API release enables developers to efficiently handle AI files with EPSF headers and update their workflows for managing diverse image formats. This code sample illustrates the feature usage in C#:
string sourceFile = Path.Combine(baseFolder, "example.ai");
string outputFilePath = Path.Combine(outputFolder, "example.png");
void AssertAreEqual(object expected, object actual)
{
if (!object.Equals(expected, actual))
{
throw new Exception("Objects are not equal.");
}
}
using (AiImage image = (AiImage)Image.Load(sourceFile))
{
AssertAreEqual(image.Layers.Length, 2);
AssertAreEqual(image.Layers[0].HasMultiLayerMasks, false);
AssertAreEqual(image.Layers[0].ColorIndex, -1);
AssertAreEqual(image.Layers[1].HasMultiLayerMasks, false);
AssertAreEqual(image.Layers[1].ColorIndex, -1);
image.Save(outputFilePath, new PngOptions());
}
Source*
Upgraded Rendering of Shape Layers
Integrate improved rendering accuracy within your PSD manipulation apps, ensuring precise representation of shape layers in your PSD files on the .NET platform. Please check out the following coding example to learn how to render shape layers using the .NET PSD library:
string sourceFile = Path.Combine(baseFolder, "ShapeLayerTest.psd");
string outputFile = Path.Combine(outputFolder, "ShapeLayerTest_output.psd");
const int ImgToPsdRatio = 256 * 65535;
using (var im = (PsdImage)Image.Load(sourceFile))
{
ShapeLayer shapeLayer = (ShapeLayer)im.Layers[2];
IPath path = shapeLayer.Path;
IPathShape[] pathShapes = path.GetItems();
List<BezierKnotRecord> knotsList = new List<BezierKnotRecord>();
foreach (IPathShape pathShape in pathShapes)
{
BezierKnotRecord[] knots = pathShape.GetItems();
knotsList.AddRange(knots);
}
// Change layer properties
var newShape = new PathShape();
BezierKnotRecord[] bezierKnots = new BezierKnotRecord[]
{
new BezierKnotRecord()
{
IsLinked = true,
Points = new Point[3]
{
PointFToResourcePoint(
new PointF(100, 100),
shapeLayer.Container.Size),
PointFToResourcePoint(
new PointF(100, 100),
shapeLayer.Container.Size),
PointFToResourcePoint(
new PointF(100, 100),
shapeLayer.Container.Size),
},
},
new BezierKnotRecord()
{
IsLinked = true,
Points = new Point[3]
{
PointFToResourcePoint(
new PointF(50, 490),
shapeLayer.Container.Size),
PointFToResourcePoint(
new PointF(100, 490),
shapeLayer.Container.Size), // Anchor point
PointFToResourcePoint(
new PointF(150, 490),
shapeLayer.Container.Size),
},
},
new BezierKnotRecord()
{
IsLinked = true,
Points = new Point[3]
{
PointFToResourcePoint(
new PointF(490, 150),
shapeLayer.Container.Size),
PointFToResourcePoint(
new PointF(490, 50),
shapeLayer.Container.Size),
PointFToResourcePoint(
new PointF(490, 20),
shapeLayer.Container.Size),
},
},
};
newShape.SetItems(bezierKnots);
List<IPathShape> newShapes = new List<IPathShape>(pathShapes);
newShapes.Add(newShape);
IPathShape[] pathShapeNew = newShapes.ToArray();
path.SetItems(pathShapeNew);
shapeLayer.Update();
im.Save(outputFile, new PsdOptions());
}
using (var im = (PsdImage)Image.Load(outputFile))
{
ShapeLayer shapeLayer = (ShapeLayer)im.Layers[2];
IPath path = shapeLayer.Path;
IPathShape[] pathShapes = path.GetItems();
List<BezierKnotRecord> knotsList = new List<BezierKnotRecord>();
foreach (IPathShape pathShape in pathShapes)
{
BezierKnotRecord[] knots = pathShape.GetItems();
knotsList.AddRange(knots);
}
AssertAreEqual(3, pathShapes.Length);
AssertAreEqual(42, shapeLayer.Left);
AssertAreEqual(14, shapeLayer.Top);
AssertAreEqual(1600, shapeLayer.Bounds.Width);
AssertAreEqual(1086, shapeLayer.Bounds.Height);
}
Point PointFToResourcePoint(PointF point, Size imageSize)
{
return new Point(
(int)Math.Round(point.Y * (ImgToPsdRatio / imageSize.Height)),
(int)Math.Round(point.X * (ImgToPsdRatio / imageSize.Width)));
}
void AssertAreEqual(object expected, object actual, string message = null)
{
if (!object.Equals(expected, actual))
{
throw new Exception(message ?? "Objects are not equal.");
}
}
Source*
Seamlessly Handle Large Files
Aspose.PSD for .NET 24.5 allows saving large PSD files exceeding 200 MB effortlessly, as we have removed the previously placed size limitations. The following code sample demonstrates how to process and save larger files in C#:
string sourceFile = Path.Combine(baseFolder, "bigfile.psd");
string outputFile = Path.Combine(outputFolder, "output_raw.psd");
PsdLoadOptions loadOptions = new PsdLoadOptions()
{
LoadEffectsResource = true,
UseDiskForLoadEffectsResource = true
};
using (var psdImage = (PsdImage)Image.Load(sourceFile, loadOptions))
{
// There should no error here
psdImage.Save(outputFile, new PsdOptions { CompressionMethod = CompressionMethod.RLE });
}
Source*
Supercharged PDF Export
Experience accurate PSD to PDF conversions as we have now addressed the issues affecting PSD to PDF export. This code sample highlights the PSD to PDF conversion in C#:
string sourceFile = Path.Combine(baseFolder, "CVFlor.psd");
string outputFile = Path.Combine(outputFolder, "_export.pdf");
using (var psdImage = (PsdImage)Image.Load(sourceFile))
{
PdfOptions saveOptions = new PdfOptions();
saveOptions.PdfCoreOptions = new PdfCoreOptions();
psdImage.Save(outputFile, saveOptions);
}
Source*
Compatibility Chinese Fonts
Implement the capability to handle Chinese fonts within your C# and VB.NET solutions using the GetFontInfoRecords
method. It prevents exceptions and verifies precise font-related information within your C# PSD file manipulation applications. This code sample explains how to process Chinese fonts with the .NET library:
var fontFolder = Path.Combine(baseFolder, "Font");
string sourceFile = Path.Combine(baseFolder, "bd-worlds-best-pink.psd");
PsdLoadOptions psdLoadOptions = new PsdLoadOptions();
psdLoadOptions.LoadEffectsResource = true;
psdLoadOptions.AllowWarpRepaint = true;
try
{
FontSettings.SetFontsFolders(new string[] { fontFolder }, true);
FontSettings.UpdateFonts();
using (PsdImage image = (PsdImage)PsdImage.Load(sourceFile, psdLoadOptions))
{
foreach (var layer in image.Layers)
{
var textLayer = layer as TextLayer;
if (textLayer != null)
{
if (textLayer.Text == "best")
{
// Without the newly added fix here will be exception because of Chinese font.
textLayer.UpdateText("SUСCESS");
}
}
}
}
}
finally
{
FontSettings.Reset();
FontSettings.UpdateFonts();
}
Source*
You can view the list of all new features, enhancements, and bug fixes introduced in this release by visiting Aspose.PSD for .NET 24.5 Release Notes.