Last active
April 4, 2024 05:38
-
-
Save aspose-com-gists/8a4c9d34ce856d1642fc7c0ce974175c to your computer and use it in GitHub Desktop.
Aspose.PSD for .NET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Enable Exporters in your initilizing module | |
Aspose.PSD.Adapters.Imaging.EnableExporters(); | |
// Load PSD, PSB or AI File using Aspose.PSD | |
using (var img = Aspose.PSD.Image.Load("MyPsdFile.psd")) | |
{ | |
// Create Save options of Adaptee | |
var webpSaveOptions = new Aspose.Imaging.ImageOptions.WebPOptions(); | |
img.Save(@"outputPath.webp", webpSaveOptions); | |
// File will be saved to WebP format using Aspose.Imaging in this example | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In your init config add enabling of Loaders | |
Aspose.PSD.Adapters.Imaging.EnableLoaders( | |
FileFormat.Jpeg2000, | |
FileFormat.Svg, | |
FileFormat.Webp); | |
// After this, all these files can be opened by Aspose.PSD without any additional code just use | |
using (var img = (PsdImage)Aspose.PSD.Image.Load("SomeFile.Webp")) { | |
// After execution of this code you'll get the PSD File created from WEBP and can apply any Aspose.PSD Filters, Layers and Adjustments including Warp Transformation | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Please reference nuget package Aspose.PSD.Adapters.Imaging | |
// In your init config add enabling of Loaders | |
Aspose.PSD.Adapters.Imaging.EnableLoaders( | |
FileFormat.Bmp, | |
FileFormat.Gif, | |
FileFormat.Jpeg2000, | |
FileFormat.Jpeg, | |
FileFormat.Png, | |
FileFormat.Svg, | |
FileFormat.Tiff, | |
FileFormat.Webp); | |
// And enable Exporters | |
Aspose.PSD.Adapters.Imaging.EnableExporters(); | |
// After this, all these files can be opened by Aspose.PSD without any additional code just use | |
using (var img = Aspose.PSD.Image.Load("SomeFile.Webp")) | |
{ | |
// After execution of this code you'll get the PSD File created from WEBP and can apply any Aspose.PSD Filters, Layers and Adjustments including Warp Transformation | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If don't need to use Loaders or Exporters provided by Adapters just disable them | |
Adapters.Imaging.DisableLoaders(); | |
Adapters.Imaging.DisableExporters(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add enabling of adapters in your init config | |
Aspose.PSD.Adapters.Imaging.EnableLoaders( | |
FileFormat.Bmp, | |
FileFormat.Gif, | |
FileFormat.Jpeg2000, | |
FileFormat.Jpeg, | |
FileFormat.Png, | |
FileFormat.Svg, | |
FileFormat.Tiff, | |
FileFormat.Webp); | |
// Additionally enable Exporters | |
Aspose.PSD.Adapters.Imaging.EnableExporters(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load file using Imaging | |
using (var imImage = Aspose.Imaging.Image.Load("input.svg")) | |
{ | |
// Call the ".ToPsdImage()" method | |
using (var psdImage = imImage.ToPsdImage()) | |
{ | |
// And then work with PsdImage | |
psdImage.AddTextLayer("Some text", new Rectangle(100, 100, 100, 50)); | |
var hue = psdImage.AddHueSaturationAdjustmentLayer(); | |
hue.Hue = 130; | |
// You'll get the PSD file with 3 layers including Text and Adjustment Layers | |
psdImage.Save("MyOutput.psd"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// To work with adapters you need both Aspose.PSD and adaptee Licenses | |
// Here is how to apply Aspose.PSD License | |
var license = new Aspose.PSD.License(); | |
license.SetLicense(@"Aspose.PSD.NET.lic"); | |
// Here is example of how to apply Adaptee License for Aspose.Imaging | |
var licImaging = new Aspose.Imaging.License(); | |
licImaging.SetLicense(@"Aspose.Imaging.NET.lic"); | |
// Then you can run any code of adapters or PSD or Imaging library |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create new Imaging-only supported Image (Can be used SVG, or any other not-supported in PSD Format) | |
using (WebPImage webp = new WebPImage(300, 300, null)) | |
{ | |
// Use Aspose.Imaging API to Edit WEBP file with Imaging-specific features | |
var gr = new Aspose.Imaging.Graphics(webp); | |
gr.Clear(Aspose.Imaging.Color.Wheat); | |
gr.DrawArc( | |
new Aspose.Imaging.Pen(Aspose.Imaging.Color.Black, 5), | |
new Aspose.Imaging.Rectangle(50, 50, 200, 200), | |
0, | |
270); | |
// Then just use ToPsdImage() method and edit file like PSD with Photoshop-like features including layers, smart filters and smart objects. | |
using (var psdImage = webp.ToPsdImage()) | |
{ | |
psdImage.AddTextLayer("Some text", new Rectangle(100, 100, 100, 50)); | |
var hue = psdImage.AddHueSaturationAdjustmentLayer(); | |
hue.Hue = 130; | |
// Save the final PSD file using Aspose.PSD | |
psdImage.Save("output.psd"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This code allows to load the specified formats | |
Aspose.PSD.Adapters.Imaging.EnableLoaders( | |
FileFormat.Svg, | |
FileFormat.Webp); | |
// This code allows you to export using adapters | |
Aspose.PSD.Adapters.Imaging.EnableExporters(); | |
// To work with adapters you need both Aspose.PSD and adaptee Licenses | |
var license = new Aspose.PSD.License(); | |
license.SetLicense(@"Aspose.PSD.NET.lic"); | |
var licImaging = new Aspose.Imaging.License(); | |
licImaging.SetLicense(@"Aspose.Imaging.NET.lic"); | |
// Aspose.Imaging loading and integration with PSD format will be provided seamless in this case. | |
using (var image = Image.Load(@"SomeFile.Webp")) | |
{ | |
// Saving in this example is provided by Aspose.PSD | |
image.Save(@"output.png", new PngOptions() { ColorType = Aspose.PSD.FileFormats.Png.PngColorType.TruecolorWithAlpha }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Gist for Aspose.PSD for .NET. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// C# code to open a psd file, updating text layers and drawing using Graphics API in a Docker container using Aspose.PSD. | |
// See https://docs.aspose.com/psd/net/how-to-run-aspose-psd-in-docker/ for complete details. | |
using Aspose.PSD; | |
using Aspose.PSD.Brushes; | |
using Aspose.PSD.FileFormats.Png; | |
using Aspose.PSD.FileFormats.Psd; | |
using Aspose.PSD.FileFormats.Psd.Layers; | |
using Aspose.PSD.ImageLoadOptions; | |
using Aspose.PSD.ImageOptions; | |
namespace AsposePsdDockerSample | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// If you want to update text, this value shoud be true, but in this case you will need the License. | |
// You can get the temporary license using this article: https://purchase.aspose.com/temporary-license | |
// Also, if you need text editing under the linux, please add to the dockerfile the following comannds | |
// to install the packages: | |
// RUN apt-get update | |
// RUN yes | apt - get install - y apt - transport - https | |
// RUN yes | apt - get install - y libgdiplus | |
// RUN yes | apt - get install - y libc6 - dev | |
var updateText = false; | |
if (updateText) | |
{ | |
var license = new License(); | |
license.SetLicense(@"Aspose.PSD.NET.lic"); | |
} | |
// If you want to use Blending Effects, please specify the following options: | |
var options = new PsdLoadOptions() { LoadEffectsResource = true }; | |
using (var img = (PsdImage)Image.Load("PsdDockerExample.psd", options)) | |
{ | |
if (updateText) | |
{ | |
var textLayer = (TextLayer)img.Layers[1]; | |
textLayer.UpdateText("Welcome to the dockerized Aspose.PSD"); | |
} | |
var regularLayer = img.Layers[2]; | |
// Did you want to use Aspose.PSD in docker under the Linux? Your wish is granted, just add the second eye to Daruma | |
var gr = new Graphics(regularLayer); | |
var brush = new SolidBrush() { Color = Color.FromArgb(1, 1, 1), Opacity = 255 }; | |
var secondEyeZone = new Rectangle(129, 77, 20, 20); | |
gr.FillEllipse(brush, secondEyeZone); | |
img.Save("Output.psd"); | |
img.Save("Output.png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Let's load Image with Picture Frame | |
using (PsdImage image = (PsdImage)Image.Load(sourceFile)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Using Layer Display Name you can find it in the PSD Image Layers List | |
private Layer FindLayerByName(PsdImage image, string name) | |
{ | |
var layers = image.Layers; | |
foreach (var layer in layers) | |
{ | |
if (string.Equals(layer.DisplayName, name, StringComparison.InvariantCultureIgnoreCase)) | |
{ | |
return layer; | |
} | |
} | |
return null; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Let's find layer that we want to replace | |
var layerToReplace = FindLayerByName(image, "LayerToReplace"); | |
var layers = new List<Layer>(image.Layers); | |
using (Stream stream = new FileStream(newLayerFile, FileMode.Open)) | |
{ | |
var newLayer = new Layer(stream); | |
// Drawing of new layer on the old | |
var graphic = new Graphics(layerToReplace); | |
graphic.Clear(Color.Empty); | |
graphic.DrawImage(newLayer, new Rectangle(new Point(), new Size(layerToReplace.Width, layerToReplace.Height))); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// We also can update text layers in PSD file. This can be used for business card create automation | |
var layerToUpdateText = (TextLayer)FindLayerByName(image, "Place the name of the picture here"); | |
// Simple way to update text | |
layerToUpdateText.UpdateText("Louis le Grand Dauphin"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Save PSD file | |
image.Save(outputFile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Finding layer that we want to replace | |
var layerToReplace = FindLayerByName(image, "LayerToReplace"); | |
var layers = new List<Layer>(image.Layers); | |
var indexOfLayer = layers.IndexOf(layerToReplace); | |
layers.Remove(layerToReplace); | |
using (Stream stream = new FileStream(newLayerFile, FileMode.Open)) | |
{ | |
var newLayer = new Layer(stream); | |
// We put new layer on the same coordinate and position in Layers as the removed layer | |
CopyLayerPosition(layerToReplace, newLayer); | |
layers.Insert(indexOfLayer, newLayer); | |
// Save list of changed layers | |
image.Layers = layers.ToArray(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Way to Copy Layer Coordinates in Aspose.PSD | |
void CopyLayerPosition(Layer from, Layer to) | |
{ | |
to.Left = from.Left; | |
to.Top = from.Top; | |
to.Right = from.Right; | |
to.Bottom = from.Bottom; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void UpdateTextLayer(PsdImage image) | |
{ | |
// We also can update text layers in PSD file. This can be used for business card create automation | |
var layerToUpdateText = (TextLayer)FindLayerByName(image, "Place the name of the picture here"); | |
// You can create comples text layers with different styles. | |
var textData = layerToUpdateText.TextData; | |
// We will use existing style of Text Layer to create new | |
var textPortion = textData.Items[0]; | |
var defaultStyle = textPortion.Style; | |
var defaultParagraph = textPortion.Paragraph; | |
ITextPortion[] newPortions = textData.ProducePortions( | |
new string[] { "Louis XIV\r", "of France" }, | |
defaultStyle, | |
defaultParagraph); | |
// Updating of default styles | |
newPortions[0].Style.FontSize = 24; | |
newPortions[0].Style.FillColor = Color.RoyalBlue; | |
newPortions[1].Style.Leading = 20; | |
// Removing old text | |
textData.RemovePortion(0); | |
// Addint new text portions | |
foreach (var newPortion in newPortions) | |
{ | |
textData.AddPortion(newPortion); | |
} | |
// Applying text update | |
textData.UpdateLayerData(); | |
// Fixes of the Layer position, because new text takes 2 rows | |
layerToUpdateText.Top = layerToUpdateText.Top - 10; | |
layerToUpdateText.Bottom = layerToUpdateText.Bottom - 10; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LayerMaskDataFull fullMask = layer.LayerMaskData as LayerMaskDataFull; | |
if (fullMask != null) | |
{ | |
var left = fullMask.EnclosingLeft; | |
var right = fullMask.EnclosingRight; | |
var top = fullMask.EnclosingTop; | |
var bottom = fullMask.EnclosingBottom; | |
var maskRectangle = fullMask.UserMaskRectangle; | |
var imageData = fullMask.UserMaskData; | |
var defaultColor = fullMask.BackgroundColor; | |
var flags = fullMask.RealFlags; | |
bool isDisabled = (flags & LayerMaskFlags.Disabled) != 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void AddRasterMask(LayerMaskData mask, LayerMaskDataShort newShortMask) | |
{ | |
LayerMaskData mask = layer.LayerMaskData; | |
LayerMaskDataFull fullMask = mask as LayerMaskDataFull; | |
var hasRasterMask = fullMask != null || | |
(mask != null && (mask.Flags & LayerMaskFlags.UserMaskFromRenderingOtherData) == 0); | |
if (hasRasterMask) | |
{ | |
Console.WriteLine("This layer has a raster mask already, updating."); | |
} | |
if (mask != null) | |
{ | |
if (fullMask != null) | |
{ | |
// let's update user raster mask in a full one. | |
fullMask.RealFlags = newMask.Flags; | |
fullMask.DefaultColor = newMask.DefaultColor; | |
fullMask.UserMaskRectangle = newMask.MaskRectangle; | |
fullMask.UserMaskData = newMask.ImageData; | |
newMask = fullMask; | |
} | |
else if ((mask.Flags & LayerMaskFlags.UserMaskFromRenderingOtherData) != 0) | |
{ | |
// let's convert the short raster mask to a full one. | |
fullMask = new LayerMaskDataFull(); | |
fullMask.Flags = mask.Flags; | |
fullMask.MaskRectangle = mask.MaskRectangle; | |
fullMask.ImageData = mask.ImageData; | |
fullMask.RealFlags = newMask.Flags; | |
fullMask.DefaultColor = newMask.DefaultColor; | |
fullMask.UserMaskRectangle = newMask.MaskRectangle; | |
fullMask.UserMaskData = newMask.ImageData; | |
newMask = fullMask; | |
} | |
} | |
// Adds or updates a mask | |
layer.AddLayerMask(newMask); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LayerMaskDataShort GetRasterMask(LayerMaskData mask) | |
{ | |
LayerMaskDataFull fullMask = mask as LayerMaskDataFull; | |
if (mask == null || | |
((mask.Flags & LayerMaskFlags.UserMaskFromRenderingOtherData) != 0 && fullMask == null)) | |
{ | |
return null; | |
} | |
if (fullMask != null) | |
{ | |
return new LayerMaskDataShort() | |
{ | |
Left = fullMask.EnclosingLeft, | |
Right = fullMask.EnclosingRight, | |
Top = fullMask.EnclosingTop, | |
Bottom = fullMask.EnclosingBottom, | |
ImageData = fullMask.UserMaskData, | |
DefaultColor = fullMask.DefaultColor, | |
Flags = fullMask.RealFlags | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void InvertMask(LayerMaskData mask) | |
{ | |
byte[] maskBytes; | |
LayerMaskDataFull fullMask = mask as LayerMaskDataFull; | |
if (fullMask == null) | |
{ | |
maskBytes = mask.ImageData; | |
} | |
else | |
{ | |
maskBytes = fullMask.UserMaskData; | |
} | |
for (int i = 0; i < maskBytes.Length; i++) | |
{ | |
maskBytes[i] = (byte)~maskBytes[i]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool GetRasterMaskState(Layer layer) | |
{ | |
var mask = layer.LayerMaskData; | |
var fullMask = mask as LayerMaskDataFull; | |
if (mask == null || ((mask.Flags & LayerMaskFlags.UserMaskFromRenderingOtherData) != 0 && | |
fullMask == null)) | |
{ | |
throw new Exception("This layer has no raster mask."); | |
} | |
if (fullMask != null) | |
{ | |
return (fullMask.RealFlags & LayerMaskFlags.Disabled) == 0; | |
} | |
else | |
{ | |
return (mask.Flags & LayerMaskFlags.Disabled) == 0; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void SetRasterMaskState(Layer layer, bool isEnabled) | |
{ | |
var mask = layer.LayerMaskData; | |
var fullMask = mask as LayerMaskDataFull; | |
if (mask == null || ((mask.Flags & LayerMaskFlags.UserMaskFromRenderingOtherData) != 0 && | |
fullMask == null)) | |
{ | |
throw new Exception("This layer has no raster mask.")); | |
} | |
if (fullMask != null) | |
{ | |
if (isEnabled) | |
{ | |
fullMask.RealFlags = fullMask.RealFlags & ~LayerMaskFlags.Disabled; | |
} | |
else | |
{ | |
fullMask.RealFlags = fullMask.RealFlags | LayerMaskFlags.Disabled; | |
} | |
} | |
else | |
{ | |
{ | |
if (isEnabled) | |
{ | |
mask.Flags = mask.Flags & ~LayerMaskFlags.Disabled; | |
} | |
else | |
{ | |
mask.Flags = mask.Flags | LayerMaskFlags.Disabled; | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LayerMaskDataShort mask = (LayerMaskDataShort)layer.LayerMaskData; | |
if ((mask.Flags & LayerMaskFlags.UserMaskFromRenderingOtherData) == 0) | |
{ | |
var left = fullMask.Left; | |
var right = fullMask.Right; | |
var top = fullMask.Top; | |
var bottom = fullMask.Bottom; | |
var maskRectangle = mask.MaskRectangle; | |
var imageData = mask.ImageData; | |
var defaultColor = newMask.DefaultColor; | |
var flags = newMask.Flags; | |
bool isDisabled = (flags & LayerMaskFlags.Disabled) != 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
layer.LayerMaskData = newMaskData; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
layer.AddLayerMask(newMaskData); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
layer.AddLayerMask(null); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool HasLayerRasterMask(Layer layer) | |
{ | |
var mask = layer.LayerMaskData; | |
var fullMask = mask as LayerMaskDataFull; | |
if (mask == null || | |
((mask.Flags & LayerMaskFlags.UserMaskFromRenderingOtherData) != 0 && fullMask == null)) | |
{ | |
return false; | |
} | |
return true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void RemoveRasterMask(Layer layer) | |
{ | |
LayerMaskData mask = layer.LayerMaskData; | |
LayerMaskDataFull fullMask = mask as LayerMaskDataFull; | |
if (mask == null || | |
((mask.Flags & LayerMaskFlags.UserMaskFromRenderingOtherData) != 0 && fullMask == null)) | |
{ | |
throw new Exception("This layer has no raster mask."); | |
} | |
if (fullMask == null) | |
{ | |
layer.AddLayerMask(null); | |
return; | |
} | |
var vectorMask = new LayerMaskDataShort(); | |
vectorMask.Flags = fullMask.Flags; | |
vectorMask.MaskRectangle = fullMask.MaskRectangle; | |
vectorMask.DefaultColor = fullMask.DefaultColor; | |
vectorMask.ImageData = fullMask.ImageData; | |
layer.AddLayerMask(vectorMask); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void UpdateRasterMask(Layer layer, Action<LayerMaskData> action) | |
{ | |
var mask = layer.LayerMaskData; | |
var fullMask = mask as LayerMaskDataFull; | |
if (mask == null || ((mask.Flags & LayerMaskFlags.UserMaskFromRenderingOtherData) != 0 && | |
fullMask == null)) | |
{ | |
throw new Exception("This layer has no raster mask."); | |
} | |
action(mask); | |
// Apply changes | |
layer.AddLayerMask(mask); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void UpdateVectorMask(Layer layer) | |
{ | |
var vectorMask = layer.LayerMaskData; | |
if (vectorMask == null || (vectorMask.Flags & LayerMaskFlags.UserMaskFromRenderingOtherData) == 0) | |
{ | |
throw new Exception("This layer has no vector mask."); | |
} | |
layer.AddLayerMask(vectorMask); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string fileName = "PathExample.psd"; | |
using (var psdImage = (PsdImage)Image.Load(fileName)) | |
{ | |
// Choose a layer with vector data that you want to edit. | |
Layer layer = psdImage.Layers[1]; | |
// Now we can use VectorPath instance and manipulate path data. | |
VectorPath vectorPath = VectorDataProvider.CreateVectorPathForLayer(layer); | |
// Apply changes from 'vectorPath' field to the layer. | |
VectorDataProvider.UpdateLayerFromVectorPath(layer, vectorPath); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Accessing a figure and points. | |
PathShape pathShape = vectorPath.Shapes[0]; | |
BezierKnot firstKnot = pathShape.Points[0]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adds new one shape | |
vectorPath.Shapes.Add(new PathShape()); | |
// or gets an existing | |
PathShape pathShape = vectorPath.Shapes[0]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add new shape with points | |
PathShape newShape = new PathShape(); | |
newShape.Points.Add(new BezierKnot(new PointF(65, 175), true)); | |
newShape.Points.Add(new BezierKnot(new PointF(65, 210), true)); | |
newShape.Points.Add(new BezierKnot(new PointF(190, 210), true)); | |
newShape.Points.Add(new BezierKnot(new PointF(190, 175), true)); | |
vectorPath.Shapes.Add(newShape); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pathShape.Points[0].Shift(0, 25); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vectorPath.FillColor = Color.Violet; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFilePath = "form_8_2l3_7.ai"; | |
string outputFilePath = "form_8_2l3_7_export"; | |
void AssertIsTrue(bool condition, string message) | |
{ | |
if (!condition) | |
{ | |
throw new FormatException(message); | |
} | |
} | |
using (AiImage image = (AiImage)Image.Load(sourceFilePath)) | |
{ | |
AiLayerSection layer0 = image.Layers[0]; | |
AssertIsTrue(layer0 != null, "Layer 0 should be not null."); | |
AssertIsTrue(layer0.Name == "Layer 4", "The Name property of the layer 0 should be `Layer 4`"); | |
AssertIsTrue(!layer0.IsTemplate, "The IsTemplate property of the layer 0 should be false."); | |
AssertIsTrue(layer0.IsLocked, "The IsLocked property of the layer 0 should be true."); | |
AssertIsTrue(layer0.IsShown, "The IsShown property of the layer 0 should be true."); | |
AssertIsTrue(layer0.IsPrinted, "The IsPrinted property of the layer 0 should be true."); | |
AssertIsTrue(!layer0.IsPreview, "The IsPreview property of the layer 0 should be false."); | |
AssertIsTrue(layer0.IsImagesDimmed, "The IsImagesDimmed property of the layer 0 should be true."); | |
AssertIsTrue(layer0.DimValue == 51, "The DimValue property of the layer 0 should be 51."); | |
AssertIsTrue(layer0.ColorNumber == 0, "The ColorNumber property of the layer 0 should be 0."); | |
AssertIsTrue(layer0.Red == 79, "The Red property of the layer 0 should be 79."); | |
AssertIsTrue(layer0.Green == 128, "The Green property of the layer 0 should be 128."); | |
AssertIsTrue(layer0.Blue == 255, "The Blue property of the layer 0 should be 255."); | |
AssertIsTrue(layer0.RasterImages.Length == 0, "The pixels length property of the raster image in the layer 0 should equals 0."); | |
AiLayerSection layer1 = image.Layers[1]; | |
AssertIsTrue(layer1 != null, "Layer 1 should be not null."); | |
AssertIsTrue(layer1.Name == "Layer 1", "The Name property of the layer 1 should be `Layer 1`"); | |
AssertIsTrue(layer1.RasterImages.Length == 1, "The length property of the raster images in the layer 1 should equals 1."); | |
AiRasterImageSection rasterImage = layer1.RasterImages[0]; | |
AssertIsTrue(rasterImage != null, "The raster image in the layer 1 should be not null."); | |
AssertIsTrue(rasterImage.Pixels != null, "The pixels property of the raster image in the layer 1 should be not null."); | |
AssertIsTrue(string.Empty == rasterImage.Name, "The Name property of the raster image in the layer 1 should be empty"); | |
AssertIsTrue(rasterImage.Pixels.Length == 100, "The pixels length property of the raster image in the layer 1 should equals 100."); | |
image.Save(outputFilePath + ".psd", new PsdOptions()); | |
image.Save(outputFilePath + ".png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + @"gauss_wiener_out.gif"; | |
// Load the noisy image | |
using (Image image = Image.Load(sourceFile)) | |
{ | |
RasterImage rasterImage = image as RasterImage; | |
if (rasterImage == null) | |
{ | |
return; | |
} | |
// Create an instance of GaussWienerFilterOptions class and set the radius size and smooth value. | |
GaussWienerFilterOptions options = new GaussWienerFilterOptions(12, 3); | |
options.Grayscale = true; | |
// Apply MedianFilterOptions filter to RasterImage object and Save the resultant image | |
rasterImage.Filter(image.Bounds, options); | |
image.Save(destName, new GifOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + @"gauss_wiener_color_out.gif"; | |
// Load the noisy image | |
using (Image image = Image.Load(sourceFile)) | |
{ | |
// Cast the image into RasterImage | |
RasterImage rasterImage = image as RasterImage; | |
if (rasterImage == null) | |
{ | |
return; | |
} | |
// Create an instance of GaussWienerFilterOptions class and set the radius size and smooth value. | |
GaussWienerFilterOptions options = new GaussWienerFilterOptions(5, 1.5); | |
options.Brightness = 1; | |
// Apply MedianFilterOptions filter to RasterImage object and Save the resultant image | |
rasterImage.Filter(image.Bounds, options); | |
image.Save(destName, new GifOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + @"median_test_denoise_out.gif"; | |
// Load the noisy image | |
using (Image image = Image.Load(sourceFile)) | |
{ | |
// Cast the image into RasterImage | |
RasterImage rasterImage = image as RasterImage; | |
if (rasterImage == null) | |
{ | |
return; | |
} | |
// Create an instance of MedianFilterOptions class and set the size, Apply MedianFilterOptions filter to RasterImage object and Save the resultant image | |
MedianFilterOptions options = new MedianFilterOptions(4); | |
rasterImage.Filter(image.Bounds, options); | |
image.Save(destName, new GifOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + @"motion_filter_out.gif"; | |
// Load the noisy image | |
using (Image image = Image.Load(sourceFile)) | |
{ | |
// Cast the image into RasterImage | |
RasterImage rasterImage = image as RasterImage; | |
if (rasterImage == null) | |
{ | |
return; | |
} | |
// Create an instance of MotionWienerFilterOptions class and set the length, smooth value and angle. | |
MotionWienerFilterOptions options = new MotionWienerFilterOptions(50, 9, 90); | |
options.Grayscale = true; | |
// Apply MedianFilterOptions filter to RasterImage object and Save the resultant image | |
rasterImage.Filter(image.Bounds, options); | |
image.Save(destName, new GifOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + @"BinarizationWithFixedThreshold_out.jpg"; | |
// Load an image | |
using (Image image = Image.Load(sourceFile)) | |
{ | |
// Cast the image to RasterCachedImage and Check if image is cached | |
RasterCachedImage rasterCachedImage = (RasterCachedImage)image; | |
if (!rasterCachedImage.IsCached) | |
{ | |
// Cache image if not already cached | |
rasterCachedImage.CacheData(); | |
} | |
// Binarize image with predefined fixed threshold and Save the resultant image | |
rasterCachedImage.BinarizeFixed(100); | |
rasterCachedImage.Save(destName, new JpegOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + @"BinarizationWithOtsuThreshold_out.jpg"; | |
// Load an image | |
using (Image image = Image.Load(sourceFile)) | |
{ | |
// Cast the image to RasterCachedImage and Check if image is cached | |
RasterCachedImage rasterCachedImage = (RasterCachedImage)image; | |
if (!rasterCachedImage.IsCached) | |
{ | |
// Cache image if not already cached | |
rasterCachedImage.CacheData(); | |
} | |
// Binarize image with Otsu Thresholding and Save the resultant image | |
rasterCachedImage.BinarizeOtsu(); | |
rasterCachedImage.Save(destName, new JpegOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + @"binarized_out.png"; | |
// Load the noisy image | |
// Load an image | |
using (PsdImage image = (PsdImage)Image.Load(sourceFile)) | |
{ | |
// Define threshold value, Call BinarizeBradley method and pass the threshold value as parameter and Save the output image | |
double threshold = 0.15; | |
image.BinarizeBradley(threshold); | |
image.Save(destName, new PngOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + @"output.tiff"; | |
using (Image image = Image.Load(sourceFile)) | |
{ | |
image.Save(destName, new TiffOptions(TiffExpectedFormat.TiffLzwCmyk)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Create a new Image. | |
using (PsdImage image = new PsdImage(500, 500)) | |
{ | |
// Fill image data. | |
int count = image.Width * image.Height; | |
int[] pixels = new int[count]; | |
int r = 0; | |
int g = 0; | |
int b = 0; | |
int channel = 0; | |
for (int i = 0; i < count; i++) | |
{ | |
if (channel % 3 == 0) | |
{ | |
r++; | |
if (r == 256) | |
{ | |
r = 0; | |
channel++; | |
} | |
} | |
else if (channel % 3 == 1) | |
{ | |
g++; | |
if (g == 256) | |
{ | |
g = 0; | |
channel++; | |
} | |
} | |
else | |
{ | |
b++; | |
if (b == 256) | |
{ | |
b = 0; | |
channel++; | |
} | |
} | |
pixels[i] = Color.FromArgb(r, g, b).ToArgb(); | |
} | |
// Save the newly created pixels. | |
image.SaveArgb32Pixels(image.Bounds, pixels); | |
// Save the newly created image. | |
image.Save(dataDir + "Default.jpg", new JpegOptions()); | |
// Update color profile. | |
StreamSource rgbprofile = new StreamSource(File.OpenRead(dataDir + "eciRGB_v2.icc")); | |
StreamSource cmykprofile = new StreamSource(File.OpenRead(dataDir + "ISOcoated_v2_FullGamut4.icc")); | |
image.RgbColorProfile = rgbprofile; | |
image.CmykColorProfile = cmykprofile; | |
// Save the resultant image with new YCCK profiles. You will notice differences in color values if compare the images. | |
JpegOptions options = new JpegOptions(); | |
options.ColorType = JpegCompressionColorMode.Cmyk; | |
image.Save(dataDir + "Cmyk_Default_profiles.jpg", options); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Create a new Image. | |
using (PsdImage image = new PsdImage(500, 500)) | |
{ | |
// Fill image data. | |
int count = image.Width * image.Height; | |
int[] pixels = new int[count]; | |
int r = 0; | |
int g = 0; | |
int b = 0; | |
int channel = 0; | |
for (int i = 0; i < count; i++) | |
{ | |
if (channel % 3 == 0) | |
{ | |
r++; | |
if (r == 256) | |
{ | |
r = 0; | |
channel++; | |
} | |
} | |
else if (channel % 3 == 1) | |
{ | |
g++; | |
if (g == 256) | |
{ | |
g = 0; | |
channel++; | |
} | |
} | |
else | |
{ | |
b++; | |
if (b == 256) | |
{ | |
b = 0; | |
channel++; | |
} | |
} | |
pixels[i] = Color.FromArgb(r, g, b).ToArgb(); | |
} | |
// Save the newly created pixels. | |
image.SaveArgb32Pixels(image.Bounds, pixels); | |
// Save the resultant image with default Icc profiles. | |
image.Save(dataDir + "Default_profiles.jpg", new JpegOptions()); | |
// Update color profile. | |
StreamSource rgbprofile = new StreamSource(File.OpenRead(dataDir + "eciRGB_v2.icc")); | |
StreamSource cmykprofile = new StreamSource(File.OpenRead(dataDir + "ISOcoated_v2_FullGamut4.icc")); | |
image.RgbColorProfile = rgbprofile; | |
image.CmykColorProfile = cmykprofile; | |
// Save the resultant image with new YCCK profiles. You will notice differences in color values if compare the images. | |
JpegOptions options = new JpegOptions(); | |
options.ColorType = JpegCompressionColorMode.Ycck; | |
image.Save(dataDir + "Ycck_profiles.jpg", options); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string dataDir = baseFolder; | |
string outputDir = output; | |
// These examples demonstrate conversion of the PSD image format to other Color Modes/BitDepth. | |
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); | |
} | |
// Saves to PSD then loads the saved file and saves to 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; | |
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 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 }); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string srcPath = dataDir + @"sample.psd"; | |
string destName = dataDir + @"export.png"; | |
// Load an existing PSD image | |
using (RasterImage image = (RasterImage)Image.Load(srcPath)) | |
{ | |
// Create an instance of Rectangle class by passing x,y and width,height | |
// Call the crop method of Image class and pass the rectangle class instance | |
image.Crop(new Rectangle(0, 0, 350, 450)); | |
// Create an instance of PngOptions class | |
PngOptions pngOptions = new PngOptions(); | |
// Call the save method, provide output path and PngOptions to convert the PSD file to PNG and save the output | |
image.Save(destName, pngOptions); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFileName = dataDir + "1.psd"; | |
string exportPathPsd = dataDir + "CropTest.psd"; | |
string exportPathPng = dataDir + "CropTest.png"; | |
using (RasterImage image = Image.Load(sourceFileName) as RasterImage) | |
{ | |
image.Crop(new Rectangle(10, 30, 100, 100)); | |
image.Save(exportPathPsd, new PsdOptions()); | |
image.Save(exportPathPng, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string imageDataPath = dataDir + @"sample.psd"; | |
try | |
{ | |
// Create the stream of the existing image file. | |
using (System.IO.FileStream fileStream = System.IO.File.Create(imageDataPath)) | |
{ | |
// Create an instance of PSD image option class. | |
using (PsdOptions psdOptions = new PsdOptions()) | |
{ | |
// Set the source property of the imaging option class object. | |
psdOptions.Source = new Sources.StreamSource(fileStream); | |
// DO PROCESSING. | |
// Following is the sample processing on the image. Un-comment to use it. | |
//using (RasterImage image = (RasterImage)Image.Create(psdOptions, 10, 10)) | |
//{ | |
// Color[] pixels = new Color[4]; | |
// for (int i = 0; i < 4; ++i) | |
// { | |
// pixels[i] = Color.FromArgb(40, 30, 20, 10); | |
// } | |
// image.SavePixels(new Rectangle(0, 0, 2, 2), pixels); | |
// image.Save(); | |
//} | |
} | |
} | |
} | |
finally | |
{ | |
// Delete the file. This statement is in the final block because in any case this statement should execute to make it sure that resource is properly disposed off. | |
System.IO.File.Delete(imageDataPath); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + @"output"; | |
// Load a PSD image and Convert the image's layers to Tiff images. | |
using (PsdImage image = (PsdImage)Image.Load(sourceFile)) | |
{ | |
// Iterate through array of PSD layers | |
for (int i = 0; i < image.Layers.Length; i++) | |
{ | |
// Get PSD layer. | |
Layer layer = image.Layers[i]; | |
// Create an instance of TIFF Option class and Save the PSD layer as TIFF image | |
TiffOptions objTiff = new TiffOptions(TiffExpectedFormat.TiffDeflateRgb); | |
layer.Save("output" + i + "_out.tif", objTiff); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + @"Grayscaling_out.jpg"; | |
// Load an image in an instance of Image | |
using (Image image = Image.Load(sourceFile)) | |
{ | |
// Cast the image to RasterCachedImage and Check if image is cached | |
RasterCachedImage rasterCachedImage = (RasterCachedImage)image; | |
if (!rasterCachedImage.IsCached) | |
{ | |
// Cache image if not already cached | |
rasterCachedImage.CacheData(); | |
} | |
// Transform image to its grayscale representation and Save the resultant image | |
rasterCachedImage.Grayscale(); | |
rasterCachedImage.Save(destName, new JpegOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + "result.png"; | |
FileStream fStream = new FileStream(sourceFile, FileMode.Open); | |
fStream.Position = 0; | |
// load PSD image and replace the non found fonts. | |
using (Image image = Image.Load(fStream)) | |
{ | |
PsdImage psdImage = (PsdImage)image; | |
MemoryStream stream = new MemoryStream(); | |
psdImage.Save(stream, new PngOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string srcPath = dataDir + @"sample.psd"; | |
string destName = dataDir + @"export"; | |
// Load an existing PSD image as Image | |
using (Image image = Image.Load(srcPath)) | |
{ | |
// Create an instance of PngOptions class | |
PngOptions pngOptions = new PngOptions(); | |
// Create an instance of BmpOptions class | |
BmpOptions bmpOptions = new BmpOptions(); | |
// Create an instance of TiffOptions class | |
TiffOptions tiffOptions = new TiffOptions(FileFormats.Tiff.Enums.TiffExpectedFormat.Default); | |
// Create an instance of GifOptions class | |
GifOptions gifOptions = new GifOptions(); | |
// Create an instance of JpegOptions class | |
JpegOptions jpegOptions = new JpegOptions(); | |
// Create an instance of Jpeg2000Options class | |
Jpeg2000Options jpeg2000Options = new Jpeg2000Options(); | |
// Call the save method, provide output path and export options to convert PSD file to various raster file formats. | |
image.Save(destName + ".png", pngOptions); | |
image.Save(destName + ".bmp", bmpOptions); | |
image.Save(destName + ".tiff", tiffOptions); | |
image.Save(destName + ".gif", gifOptions); | |
image.Save(destName + ".jpeg", jpegOptions); | |
image.Save(destName + ".jp2", jpeg2000Options); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string destName = OutputDir + @"RenderTextWithDifferentColorsInTextLayer_out.png"; | |
// Load the noisy image | |
using (var psdImage = (PsdImage)Image.Load(sourceFile)) | |
{ | |
var txtLayer = (TextLayer)psdImage.Layers[1]; | |
txtLayer.TextData.UpdateLayerData(); | |
PngOptions pngOptions = new PngOptions(); | |
pngOptions.ColorType = PngColorType.TruecolorWithAlpha; | |
psdImage.Save(destName, pngOptions); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
{ | |
/// <summary> | |
/// The path to the input image. | |
/// </summary> | |
private readonly string inputPath; | |
/// <summary> | |
/// The path to the output image. | |
/// </summary> | |
private readonly string outputPath; | |
/// <summary> | |
/// The interrupt monitor. | |
/// </summary> | |
private readonly InterruptMonitor monitor; | |
/// <summary> | |
/// The save options. | |
/// </summary> | |
private readonly ImageOptionsBase saveOptions; | |
/// <summary> | |
/// Initializes a new instance of the <see cref="SaveImageWorker" /> class. | |
/// </summary> | |
/// <param name="inputPath">The path to the input image.</param> | |
/// <param name="outputPath">The path to the output image.</param> | |
/// <param name="saveOptions">The save options.</param> | |
/// <param name="monitor">The interrupt monitor.</param> | |
public SaveImageWorker(string inputPath, string outputPath, ImageOptionsBase saveOptions, InterruptMonitor monitor) | |
{ | |
this.inputPath = inputPath; | |
this.outputPath = outputPath; | |
this.saveOptions = saveOptions; | |
this.monitor = monitor; | |
} | |
/// <summary> | |
/// Tries to convert image from one format to another. Handles interruption. | |
/// </summary> | |
public void ThreadProc() | |
{ | |
using (Image image = Image.Load(this.inputPath)) | |
{ | |
InterruptMonitor.ThreadLocalInstance = this.monitor; | |
try | |
{ | |
image.Save(this.outputPath, this.saveOptions); | |
} | |
catch (OperationInterruptedException e) | |
{ | |
Console.WriteLine("The save thread #{0} finishes at {1}", Thread.CurrentThread.ManagedThreadId, DateTime.Now); | |
Console.WriteLine(e); | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine(e); | |
} | |
finally | |
{ | |
InterruptMonitor.ThreadLocalInstance = null; | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + "result.png"; | |
// load PSD image and replace the non found fonts. | |
using (Image image = Image.Load(sourceFile)) | |
{ | |
PsdImage psdImage = (PsdImage)image; | |
psdImage.Save(destName, new PngOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + "result.png"; | |
// load PSD image and replace the non found fonts. | |
using (Image image = Image.Load(sourceFile)) | |
{ | |
PsdImage psdImage = (PsdImage)image; | |
MemoryStream stream = new MemoryStream(); | |
psdImage.Save(stream, new PngOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFileName = "sample_konstanting.psd"; | |
string[] outputs = new string[] | |
{ | |
"replacedfont0.tiff", | |
"replacedfont1.png", | |
"replacedfont2.jpg" | |
}; | |
using (PsdImage image = (PsdImage)Image.Load(sourceFileName, new PsdLoadOptions())) | |
{ | |
// This way you can use different fonts for different outputs | |
image.Save(outputs[0], new TiffOptions(TiffExpectedFormat.TiffJpegRgb) { DefaultReplacementFont = "Arial" }); | |
image.Save(outputs[1], new PngOptions { DefaultReplacementFont = "Verdana" }); | |
image.Save(outputs[2], new JpegOptions { DefaultReplacementFont = "Times New Roman" }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
ImageOptionsBase saveOptions = new PngOptions(); | |
InterruptMonitor monitor = new InterruptMonitor(); | |
string source = "big2.psb"; | |
string output = "big_out.png"; | |
SaveImageWorker worker = new SaveImageWorker(source, output, saveOptions, monitor); | |
Thread thread = new Thread(new ThreadStart(worker.ThreadProc)); | |
try | |
{ | |
thread.Start(); | |
// The timeout should be less than the time required for full image conversion (without interruption). | |
Thread.Sleep(3000); | |
// Interrupt the process | |
monitor.Interrupt(); | |
Console.WriteLine("Interrupting the save thread #{0} at {1}", thread.ManagedThreadId, System.DateTime.Now); | |
// Wait for interruption... | |
thread.Join(); | |
} | |
finally | |
{ | |
// Delete the output file. | |
if (File.Exists(output)) | |
{ | |
File.Delete(output); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Create an instance of Memory stream class. | |
using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream()) | |
{ | |
// Create an instance of Stream container class and assign memory stream object. | |
using (StreamContainer streamContainer = new StreamContainer(memoryStream)) | |
{ | |
// check if the access to the stream source is synchronized. | |
lock (streamContainer.SyncRoot) | |
{ | |
// do work | |
// now access to source MemoryStream is synchronized | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Add color overlay layer effect at runtime | |
string sourceFileName = dataDir + "ThreeRegularLayers.psd"; | |
string exportPath = dataDir + "ThreeRegularLayersChanged.psd"; | |
var loadOptions = new PsdLoadOptions() | |
{ | |
LoadEffectsResource = true | |
}; | |
using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) | |
{ | |
var effect = im.Layers[1].BlendingOptions.AddColorOverlay(); | |
effect.Color = Color.Green; | |
effect.Opacity = 128; | |
effect.BlendMode = BlendMode.Normal; | |
im.Save(exportPath); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + @"AdjustBrightness_out.tiff"; | |
using (var image = (PsdImage)Image.Load(sourceFile)) | |
{ | |
RasterCachedImage rasterImage = image; | |
// Set the brightness value. The accepted values of brightness are in the range [-255, 255]. | |
rasterImage.AdjustBrightness(-50); | |
TiffOptions tiffOptions = new TiffOptions(TiffExpectedFormat.Default); | |
rasterImage.Save(destName, tiffOptions); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + @"AdjustContrast_out.tiff"; | |
// Load an existing image into an instance of RasterImage class | |
using (var image = Image.Load(sourceFile)) | |
{ | |
// Cast object of Image to RasterImage | |
RasterImage rasterImage = (RasterImage)image; | |
// Check if RasterImage is cached and Cache RasterImage for better performance | |
if (!rasterImage.IsCached) | |
{ | |
rasterImage.CacheData(); | |
} | |
// Adjust the contrast | |
rasterImage.AdjustContrast(50); | |
// Create an instance of TiffOptions for the resultant image, Set various properties for the object of TiffOptions and Save the resultant image to TIFF format | |
TiffOptions tiffOptions = new TiffOptions(TiffExpectedFormat.Default); | |
tiffOptions.BitsPerSample = new ushort[] { 8, 8, 8 }; | |
tiffOptions.Photometric = TiffPhotometrics.Rgb; | |
rasterImage.Save(destName, tiffOptions); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + @"AdjustGamma_out.tiff"; | |
// Load an existing image into an instance of RasterImage class | |
using (var image = Image.Load(sourceFile)) | |
{ | |
// Cast object of Image to RasterImage | |
RasterImage rasterImage = (RasterImage)image; | |
// Check if RasterImage is cached and Cache RasterImage for better performance | |
if (!rasterImage.IsCached) | |
{ | |
rasterImage.CacheData(); | |
} | |
// Adjust the gamma | |
rasterImage.AdjustGamma(2.2f, 2.2f, 2.2f); | |
// Create an instance of TiffOptions for the resultant image, Set various properties for the object of TiffOptions and Save the resultant image to TIFF format | |
TiffOptions tiffOptions = new TiffOptions(TiffExpectedFormat.Default); | |
tiffOptions.BitsPerSample = new ushort[] { 8, 8, 8 }; | |
tiffOptions.Photometric = TiffPhotometrics.Rgb; | |
rasterImage.Save(destName, tiffOptions); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + @"BlurAnImage_out.gif"; | |
// Load an existing image into an instance of RasterImage class | |
using (var image = Image.Load(sourceFile)) | |
{ | |
// Convert the image into RasterImage, | |
//Pass Bounds[rectangle] of image and GaussianBlurFilterOptions instance to Filter method and Save the results | |
RasterImage rasterImage = (RasterImage)image; | |
rasterImage.Filter(rasterImage.Bounds, new GaussianBlurFilterOptions(15, 15)); | |
rasterImage.Save(destName, new GifOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
var outputPath = dataDir + "ColorBalance_out.psd"; | |
using (var im = (FileFormats.Psd.PsdImage)Image.Load(filePath)) | |
{ | |
foreach (var layer in im.Layers) | |
{ | |
var cbLayer = layer as ColorBalanceAdjustmentLayer; | |
if (cbLayer != null) | |
{ | |
cbLayer.ShadowsCyanRedBalance = 30; | |
cbLayer.ShadowsMagentaGreenBalance = -15; | |
cbLayer.ShadowsYellowBlueBalance = 40; | |
cbLayer.MidtonesCyanRedBalance = -90; | |
cbLayer.MidtonesMagentaGreenBalance = -25; | |
cbLayer.MidtonesYellowBlueBalance = 20; | |
cbLayer.HighlightsCyanRedBalance = -30; | |
cbLayer.HighlightsMagentaGreenBalance = 67; | |
cbLayer.HighlightsYellowBlueBalance = -95; | |
cbLayer.PreserveLuminosity = true; | |
} | |
} | |
im.Save(outputPath); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// ColorOverlay effect editing | |
string sourceFileName = dataDir + "ColorOverlay.psd"; | |
string psdPathAfterChange = dataDir + "ColorOverlayChanged.psd"; | |
var loadOptions = new PsdLoadOptions() | |
{ | |
LoadEffectsResource = true | |
}; | |
using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) | |
{ | |
var colorOverlay = (ColorOverlayEffect)(im.Layers[1].BlendingOptions.Effects[0]); | |
if (colorOverlay.Color != Color.Red || | |
colorOverlay.Opacity != 153) | |
{ | |
throw new Exception("Color overlay read wrong"); | |
} | |
colorOverlay.Color = Color.Green; | |
colorOverlay.Opacity = 128; | |
im.Save(psdPathAfterChange); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Create an instance of PsdOptions and set its various properties | |
PsdOptions imageOptions = new PsdOptions(); | |
// Create an instance of FileCreateSource and assign it to Source property | |
imageOptions.Source = new FileCreateSource(dataDir + "Two_images_result_out.psd", false); | |
// Create an instance of Image and define canvas size | |
using (var image = Image.Create(imageOptions, 600, 600)) | |
{ | |
// Create and initialize an instance of Graphics, Clear the image surface with white color and Draw Image | |
var graphics = new Graphics(image); | |
graphics.Clear(Color.White); | |
graphics.DrawImage(Image.Load(dataDir + "example1.psd"), 0, 0, 300, 600); | |
graphics.DrawImage(Image.Load(dataDir + "example2.psd"), 300, 0, 300, 600); | |
image.Save(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Specify the size of image by defining a Rectangle | |
Rectangle rect = new Rectangle(0, 0, 100, 200); | |
// Create the brand new image just for sample purposes | |
using (var image = new PsdImage(rect.Width, rect.Height)) | |
{ | |
// Create an instance of XMP-Header | |
XmpHeaderPi xmpHeader = new XmpHeaderPi(Guid.NewGuid().ToString()); | |
// Create an instance of Xmp-TrailerPi, XMPmeta class to set different attributes | |
XmpTrailerPi xmpTrailer = new XmpTrailerPi(true); | |
XmpMeta xmpMeta = new XmpMeta(); | |
xmpMeta.AddAttribute("Author", "Mr Smith"); | |
xmpMeta.AddAttribute("Description", "The fake metadata value"); | |
// Create an instance of XmpPacketWrapper that contains all metadata | |
XmpPacketWrapper xmpData = new XmpPacketWrapper(xmpHeader, xmpTrailer, xmpMeta); | |
// Create an instacne of Photoshop package and set photoshop attributes | |
PhotoshopPackage photoshopPackage = new PhotoshopPackage(); | |
photoshopPackage.SetCity("London"); | |
photoshopPackage.SetCountry("England"); | |
photoshopPackage.SetColorMode(ColorMode.Rgb); | |
photoshopPackage.SetCreatedDate(DateTime.UtcNow); | |
// Add photoshop package into XMP metadata | |
xmpData.AddPackage(photoshopPackage); | |
// Create an instacne of DublinCore package and set dublinCore attributes | |
DublinCorePackage dublinCorePackage = new DublinCorePackage(); | |
dublinCorePackage.SetAuthor("Mudassir Fayyaz"); | |
dublinCorePackage.SetTitle("Confessions of a Man Insane Enough to Live With the Beasts"); | |
dublinCorePackage.AddValue("dc:movie", "Barfly"); | |
// Add dublinCore Package into XMP metadata | |
xmpData.AddPackage(dublinCorePackage); | |
using (var ms = new MemoryStream()) | |
{ | |
// Update XMP metadata into image and Save image on the disk or in memory stream | |
image.XmpData = xmpData; | |
image.Save(ms); | |
image.Save(dataDir + "ee.psd"); | |
ms.Seek(0, System.IO.SeekOrigin.Begin); | |
// Load the image from memory stream or from disk to read/get the metadata | |
using (var img = (PsdImage)Image.Load(ms)) | |
{ | |
// Getting the XMP metadata | |
XmpPacketWrapper imgXmpData = img.XmpData; | |
foreach (XmpPackage package in imgXmpData.Packages) | |
{ | |
// Use package data ... | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Creates an instance of PsdOptions and set its various properties | |
PsdOptions psdOptions = new PsdOptions(); | |
psdOptions.CompressionMethod = CompressionMethod.RLE; | |
// Define the source property for the instance of PsdOptions. Second boolean parameter determines if the file is temporal or not | |
psdOptions.Source = new FileCreateSource(desName, false); | |
// Creates an instance of Image and call Create method by passing the PsdOptions object | |
using (Image image = Image.Create(psdOptions, 500, 500)) | |
{ | |
image.Save(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string desName = dataDir + "CreatingImageUsingStream_out.bmp"; | |
// Creates an instance of BmpOptions and set its various properties | |
BmpOptions ImageOptions = new BmpOptions(); | |
ImageOptions.BitsPerPixel = 24; | |
// Create an instance of System.IO.Stream | |
Stream stream = new FileStream(dataDir + "sample_out.bmp", FileMode.Create); | |
// Define the source property for the instance of BmpOptions Second boolean parameter determines if the Stream is disposed once get out of scope | |
ImageOptions.Source = new StreamSource(stream, true); | |
// Creates an instance of Image and call Create method by passing the BmpOptions object | |
using (Image image = Image.Create(ImageOptions, 500, 500)) | |
{ | |
// Do some image processing | |
image.Save(desName); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + @"CroppingByRectangle_out.jpg"; | |
// Load an existing image into an instance of RasterImage class | |
using (RasterImage rasterImage = (RasterImage)Image.Load(sourceFile)) | |
{ | |
if (!rasterImage.IsCached) | |
{ | |
rasterImage.CacheData(); | |
} | |
// Create an instance of Rectangle class with desired size, | |
//Perform the crop operation on object of Rectangle class and Save the results to disk | |
Rectangle rectangle = new Rectangle(20, 20, 20, 20); | |
rasterImage.Crop(rectangle); | |
rasterImage.Save(destName, new JpegOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + @"CroppingByShifts_out.jpg"; | |
// Load an existing image into an instance of RasterImage class | |
using (RasterImage rasterImage = (RasterImage)Image.Load(sourceFile)) | |
{ | |
// Before cropping, the image should be cached for better performance | |
if (!rasterImage.IsCached) | |
{ | |
rasterImage.CacheData(); | |
} | |
// Define shift values for all four sides | |
int leftShift = 10; | |
int rightShift = 10; | |
int topShift = 10; | |
int bottomShift = 10; | |
// Based on the shift values, apply the cropping on image Crop method will shift the image bounds toward the center of image and Save the results to disk | |
rasterImage.Crop(leftShift, rightShift, topShift, bottomShift); | |
rasterImage.Save(destName, new JpegOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + @"SampleImage_out.bmp"; | |
// Load an existing image into an instance of RasterImage class | |
using (var image = (PsdImage)Image.Load(sourceFile)) | |
{ | |
// Peform Floyd Steinberg dithering on the current image and Save the resultant image | |
image.Dither(DitheringMethod.ThresholdDithering, 4); | |
image.Save(destName, new BmpOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"example1.psd"; | |
string destName = dataDir + @"jpeg_out.jpg"; | |
// Load an image in an instance of Image and Setting for image data to be cashed | |
using (RasterImage rasterImage = (RasterImage)Image.Load(sourceFile)) | |
{ | |
rasterImage.CacheData(); | |
// Create an instance of Rectangle class and define X,Y and Width, height of the rectangle, and Save output image | |
Rectangle destRect = new Rectangle { X = -200, Y = -200, Width = 300, Height = 300 }; | |
rasterImage.Save(destName, new JpegOptions(), destRect); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFileName = "sample_konstanting.psd"; | |
string[] outputs = new string[] | |
{ | |
"replacedfont0.tiff", | |
"replacedfont1.png", | |
"replacedfont2.jpg" | |
}; | |
using (PsdImage image = (PsdImage)Image.Load(sourceFileName, new PsdLoadOptions())) | |
{ | |
// This way you can use different fonts for different outputs | |
image.Save(outputs[0], new TiffOptions(TiffExpectedFormat.TiffJpegRgb) { DefaultReplacementFont = "Arial" }); | |
image.Save(outputs[1], new PngOptions { DefaultReplacementFont = "Verdana" }); | |
image.Save(outputs[2], new JpegOptions { DefaultReplacementFont = "Times New Roman" }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
using (PsdImage image = (PsdImage)Image.Load(dataDir + "sample.psd")) | |
{ | |
image.Save("NoFont.psd"); | |
} | |
Console.WriteLine("You have 2 minutes to install the font"); | |
Thread.Sleep(TimeSpan.FromMinutes(2)); | |
OpenTypeFontsCache.UpdateCache(); | |
using (PsdImage image = (PsdImage)Image.Load(dataDir + @"sample.psd")) | |
{ | |
image.Save(dataDir + "HasFont.psd"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string destNameCubicConvolution = dataDir + "ResamplerCubicConvolutionStripes_after.psd"; | |
// Load an existing image into an instance of PsdImage class | |
using (PsdImage image = (PsdImage)Image.Load(sourceFile)) | |
{ | |
image.Resize(300, 300, ResizeType.CubicConvolution); | |
image.Save(destNameCubicConvolution, new PsdOptions(image)); | |
} | |
string destNameCatmullRom = dataDir + "ResamplerCatmullRomStripes_after.psd"; | |
// Load an existing image into an instance of PsdImage class | |
using (PsdImage image = (PsdImage)Image.Load(sourceFile)) | |
{ | |
image.Resize(300, 300, ResizeType.CatmullRom); | |
image.Save(destNameCatmullRom, new PsdOptions(image)); | |
} | |
string destNameMitchell = "ResamplerMitchellStripes_after.psd"; | |
// Load an existing image into an instance of PsdImage class | |
using (PsdImage image = (PsdImage)Image.Load(sourceFile)) | |
{ | |
image.Resize(300, 300, ResizeType.Mitchell); | |
image.Save(destNameMitchell, new PsdOptions(image)); | |
} | |
string destNameCubicBSpline = "ResamplerCubicBSplineStripes_after.psd"; | |
// Load an existing image into an instance of PsdImage class | |
using (PsdImage image = (PsdImage)Image.Load(sourceFile)) | |
{ | |
image.Resize(300, 300, ResizeType.CubicBSpline); | |
image.Save(destNameCubicBSpline, new PsdOptions(image)); | |
} | |
string destNameSinC = "ResamplerSinCStripes_after.psd"; | |
// Load an existing image into an instance of PsdImage class | |
using (PsdImage image = (PsdImage)Image.Load(sourceFile)) | |
{ | |
image.Resize(300, 300, ResizeType.SinC); | |
image.Save(destNameSinC, new PsdOptions(image)); | |
} | |
string destNameBell = "ResamplerBellStripes_after.psd"; | |
// Load an existing image into an instance of PsdImage class | |
using (PsdImage image = (PsdImage)Image.Load(sourceFile)) | |
{ | |
image.Resize(300, 300, ResizeType.Bell); | |
image.Save(destNameBell, new PsdOptions(image)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + @"anim_lossy-200.gif"; | |
GifOptions gifExport = new GifOptions(); | |
// Load an existing image into an instance of RasterImage class | |
using (var image = Image.Load(sourceFile)) | |
{ | |
gifExport.MaxDiff = 80; | |
image.Save("anim_lossy-80.gif", gifExport); | |
gifExport.MaxDiff = 200; | |
image.Save(destName, gifExport); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
var outputPath = dataDir + "InvertStripes_after.psd"; | |
using (var im = (PsdImage)Image.Load(filePath)) | |
{ | |
im.AddInvertAdjustmentLayer(); | |
im.Save(outputPath); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string pngExportPath = dataDir + "ColorOverlayresult.png"; | |
var loadOptions = new PsdLoadOptions() | |
{ | |
LoadEffectsResource = true | |
}; | |
using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) | |
//using (var im = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
var colorOverlay = (ColorOverlayEffect)(im.Layers[1].BlendingOptions.Effects[0]); | |
if (colorOverlay.Color != Color.Red || | |
colorOverlay.Opacity != 153) | |
{ | |
throw new Exception("Color overlay read wrong"); | |
} | |
// Save PNG | |
var saveOptions = new PngOptions(); | |
saveOptions.ColorType = PngColorType.TruecolorWithAlpha; | |
im.Save(pngExportPath, saveOptions); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string pngExportPath = dataDir + "Shadowchanged1.png"; | |
var loadOptions = new PsdLoadOptions() | |
{ | |
LoadEffectsResource = true | |
}; | |
using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) | |
{ | |
var shadowEffect = (DropShadowEffect)(im.Layers[1].BlendingOptions.Effects[0]); | |
if ((shadowEffect.Color != Color.Black) || | |
(shadowEffect.Opacity != 255) || | |
(shadowEffect.Distance != 3) || | |
(shadowEffect.Size != 7) || | |
(shadowEffect.UseGlobalLight != true) || | |
(shadowEffect.Angle != 90) || | |
(shadowEffect.Spread != 0) || | |
(shadowEffect.Noise != 0)) | |
{ | |
throw new Exception("Shadow Effect properties were read wrong"); | |
} | |
// Save PNG | |
var saveOptions = new PngOptions(); | |
saveOptions.ColorType = PngColorType.TruecolorWithAlpha; | |
im.Save(pngExportPath, saveOptions); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + @"SimpleResizeImageProportionally_out.png"; | |
// Load an existing image into an instance of RasterImage class | |
using (Image image = Image.Load(sourceFile)) | |
{ | |
if (!image.IsCached) | |
{ | |
image.CacheData(); | |
} | |
// Specifying width and height | |
int newWidth = image.Width / 2; | |
image.ResizeWidthProportionally(newWidth); | |
int newHeight = image.Height / 2; | |
image.ResizeHeightProportionally(newHeight); | |
image.Save(destName, new PngOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + @"ResizingwithResizeTypeEnumeration_out.jpg"; | |
// Load an existing image into an instance of RasterImage class | |
using (Image image = Image.Load(sourceFile)) | |
{ | |
image.Resize(300, 300, ResizeType.LanczosResample); | |
image.Save(destName, new JpegOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + @"RotatingAnImage_out.jpg"; | |
// Load an existing image into an instance of RasterImage class | |
using (Image image = Image.Load(sourceFile)) | |
{ | |
image.RotateFlip(RotateFlipType.Rotate270FlipNone); | |
image.Save(destName, new JpegOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + @"RotatingImageOnSpecificAngle_out.jpg"; | |
// Load an image to be rotated in an instance of RasterImage | |
using (RasterImage image = (RasterImage)Image.Load(sourceFile)) | |
{ | |
// Before rotation, the image should be cached for better performance | |
if (!image.IsCached) | |
{ | |
image.CacheData(); | |
} | |
// Perform the rotation on 20 degree while keeping the image size proportional with red background color and Save the result to a new file | |
image.Rotate(20f, true, Color.Red); | |
image.Save(destName, new JpegOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + @"SimpleResizing_out.jpg"; | |
// Load an existing image into an instance of RasterImage class | |
using (Image image = Image.Load(sourceFile)) | |
{ | |
image.Resize(300, 300); | |
image.Save(destName, new JpegOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
{ | |
"Normal", | |
"Dissolve", | |
"Darken", | |
"Multiply", | |
"ColorBurn", | |
"LinearBurn", | |
"DarkerColor", | |
"Lighten", | |
"Screen", | |
"ColorDodge", | |
"LinearDodgeAdd", | |
"LightenColor", | |
"Overlay", | |
"SoftLight", | |
"HardLight", | |
"VividLight", | |
"LinearLight", | |
"PinLight", | |
"HardMix", | |
"Difference", | |
"Exclusion", | |
"Subtract", | |
"Divide", | |
"Hue", | |
"Saturation", | |
"Color", | |
"Luminosity", | |
}; | |
foreach (var fileName in files) | |
{ | |
using (var im = (PsdImage)Image.Load(dataDir + fileName + ".psd")) | |
{ | |
// Export to PNG | |
var saveOptions = new PngOptions(); | |
saveOptions.ColorType = PngColorType.TruecolorWithAlpha; | |
var pngExportPath100 = "BlendMode" + fileName + "_Test100.png"; | |
im.Save(pngExportPath100, saveOptions); | |
// Set opacity 50% | |
im.Layers[1].Opacity = 127; | |
var pngExportPath50 = "BlendMode" + fileName + "_Test50.png"; | |
im.Save(pngExportPath50, saveOptions); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
void AreEqual(object expected, object actual) | |
{ | |
if (!object.Equals(expected, actual)) | |
{ | |
throw new Exception("Values are not equal."); | |
} | |
} | |
string srcFile = baseFolder + "GST-CHALLAN(2)1..psd"; | |
string output = outputFolder + "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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
void AssertAreEqual(object actual, object expected) | |
{ | |
if (!object.Equals(actual, expected)) | |
{ | |
throw new FormatException(string.Format("Actual value {0} are not equal to expected {1}.", actual, expected)); | |
} | |
} | |
var sourceFilePath = baseFolder + "LayeredSmartObjects8bit2.psd"; | |
using (PsdImage image = (PsdImage)Image.Load(sourceFilePath)) | |
{ | |
UnitArrayStructure verticalStructure = null; | |
foreach (Layer imageLayer in image.Layers) | |
{ | |
foreach (var imageResource in imageLayer.Resources) | |
{ | |
var resource = imageResource as PlLdResource; | |
if (resource != null && resource.IsCustom) | |
{ | |
foreach (OSTypeStructure structure in resource.Items) | |
{ | |
if (structure.KeyName.ClassName == "customEnvelopeWarp") | |
{ | |
AssertAreEqual(typeof(DescriptorStructure), structure.GetType()); | |
var custom = (DescriptorStructure)structure; | |
AssertAreEqual(custom.Structures.Length, 1); | |
var mesh = custom.Structures[0]; | |
AssertAreEqual(typeof(ObjectArrayStructure), mesh.GetType()); | |
var meshObjectArray = (ObjectArrayStructure)mesh; | |
AssertAreEqual(meshObjectArray.Structures.Length, 2); | |
var vertical = meshObjectArray.Structures[1]; | |
AssertAreEqual(typeof(UnitArrayStructure), vertical.GetType()); | |
verticalStructure = (UnitArrayStructure)vertical; | |
AssertAreEqual(verticalStructure.UnitType, UnitTypes.Pixels); | |
AssertAreEqual(verticalStructure.ValueCount, 16); | |
break; | |
} | |
} | |
} | |
} | |
} | |
AssertAreEqual(true, verticalStructure != null); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string psdPathAfterChange = dataDir + "ShadowChanged.psd"; | |
var loadOptions = new PsdLoadOptions() | |
{ | |
LoadEffectsResource = true | |
}; | |
using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) | |
{ | |
var shadowEffect = (DropShadowEffect)(im.Layers[1].BlendingOptions.Effects[0]); | |
if ((shadowEffect.Color != Color.Black) || | |
(shadowEffect.Opacity != 255) || | |
(shadowEffect.Distance != 3) || | |
(shadowEffect.Size != 7) || | |
(shadowEffect.UseGlobalLight != true) || | |
(shadowEffect.Angle != 90) || | |
(shadowEffect.Spread != 0) || | |
(shadowEffect.Noise != 0)) | |
{ | |
throw new Exception("Shadow Effect was read wrong"); | |
} | |
shadowEffect.Color = Color.Green; | |
shadowEffect.Opacity = 128; | |
shadowEffect.Distance = 11; | |
shadowEffect.UseGlobalLight = false; | |
shadowEffect.Size = 9; | |
shadowEffect.Angle = 45; | |
shadowEffect.Spread = 3; | |
shadowEffect.Noise = 50; | |
im.Save(psdPathAfterChange); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + @"sample.psd"; | |
string destName = dataDir + @"AdjustBrightness_out.tiff"; | |
// Load an existing image into an instance of RasterImage class | |
using (PsdImage image = (PsdImage)Image.Load(sourceFile)) | |
{ | |
float opacity = image.ImageOpacity; | |
Console.WriteLine(opacity); | |
if (opacity == 0) | |
{ | |
// The image is fully transparent. | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
{ | |
if (!condition) | |
{ | |
throw new FormatException(message); | |
} | |
} | |
// Gradient overlay effect. Example | |
string sourceFileName = dataDir + "GradientOverlay.psd"; | |
string exportPath = dataDir + "GradientOverlayChanged.psd"; | |
var loadOptions = new PsdLoadOptions() | |
{ | |
LoadEffectsResource = true | |
}; | |
using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) | |
{ | |
var gradientOverlay = (GradientOverlayEffect)im.Layers[1].BlendingOptions.Effects[0]; | |
AssertIsTrue(gradientOverlay.BlendMode == BlendMode.Normal); | |
AssertIsTrue(gradientOverlay.Opacity == 255); | |
AssertIsTrue(gradientOverlay.IsVisible == true); | |
var settings = gradientOverlay.Settings; | |
AssertIsTrue(settings.Color == Color.Empty); | |
AssertIsTrue(settings.FillType == FillType.Gradient); | |
AssertIsTrue(settings.AlignWithLayer == true); | |
AssertIsTrue(settings.GradientType == GradientType.Linear); | |
AssertIsTrue(Math.Abs(33 - settings.Angle) < 0.001, "Angle is incorrect"); | |
AssertIsTrue(settings.Dither == false); | |
AssertIsTrue(Math.Abs(129 - settings.HorizontalOffset) < 0.001, "Horizontal offset is incorrect"); | |
AssertIsTrue(Math.Abs(156 - settings.VerticalOffset) < 0.001, "Vertical offset is incorrect"); | |
AssertIsTrue(settings.Reverse == false); | |
// Color Points | |
var colorPoints = settings.ColorPoints; | |
AssertIsTrue(colorPoints.Length == 3); | |
AssertIsTrue(colorPoints[0].Color == Color.FromArgb(9, 0, 178)); | |
AssertIsTrue(colorPoints[0].Location == 0); | |
AssertIsTrue(colorPoints[0].MedianPointLocation == 50); | |
AssertIsTrue(colorPoints[1].Color == Color.Red); | |
AssertIsTrue(colorPoints[1].Location == 2048); | |
AssertIsTrue(colorPoints[1].MedianPointLocation == 50); | |
AssertIsTrue(colorPoints[2].Color == Color.FromArgb(255, 252, 0)); | |
AssertIsTrue(colorPoints[2].Location == 4096); | |
AssertIsTrue(colorPoints[2].MedianPointLocation == 50); | |
// Transparency points | |
var transparencyPoints = settings.TransparencyPoints; | |
AssertIsTrue(transparencyPoints.Length == 2); | |
AssertIsTrue(transparencyPoints[0].Location == 0); | |
AssertIsTrue(transparencyPoints[0].MedianPointLocation == 50); | |
AssertIsTrue(transparencyPoints[0].Opacity == 100); | |
AssertIsTrue(transparencyPoints[1].Location == 4096); | |
AssertIsTrue(transparencyPoints[1].MedianPointLocation == 50); | |
AssertIsTrue(transparencyPoints[1].Opacity == 100); | |
// Test editing | |
settings.Color = Color.Green; | |
gradientOverlay.Opacity = 193; | |
gradientOverlay.BlendMode = BlendMode.Lighten; | |
settings.AlignWithLayer = false; | |
settings.GradientType = GradientType.Radial; | |
settings.Angle = 45; | |
settings.Dither = true; | |
settings.HorizontalOffset = 15; | |
settings.VerticalOffset = 11; | |
settings.Reverse = true; | |
// Add new color point | |
var colorPoint = settings.AddColorPoint(); | |
colorPoint.Color = Color.Green; | |
colorPoint.Location = 4096; | |
colorPoint.MedianPointLocation = 75; | |
// Change location of previous point | |
settings.ColorPoints[2].Location = 3000; | |
// Add new transparency point | |
var transparencyPoint = settings.AddTransparencyPoint(); | |
transparencyPoint.Opacity = 25; | |
transparencyPoint.MedianPointLocation = 25; | |
transparencyPoint.Location = 4096; | |
// Change location of previous transparency point | |
settings.TransparencyPoints[1].Location = 2315; | |
im.Save(exportPath); | |
} | |
// Test file after edit | |
using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) | |
{ | |
var gradientOverlay = (GradientOverlayEffect)im.Layers[1].BlendingOptions.Effects[0]; | |
try | |
{ | |
AssertIsTrue(gradientOverlay.BlendMode == BlendMode.Lighten); | |
AssertIsTrue(gradientOverlay.Opacity == 193); | |
AssertIsTrue(gradientOverlay.IsVisible == true); | |
var fillSettings = gradientOverlay.Settings; | |
AssertIsTrue(fillSettings.Color == Color.Empty); | |
AssertIsTrue(fillSettings.FillType == FillType.Gradient); | |
// Check color points | |
AssertIsTrue(fillSettings.ColorPoints.Length == 4); | |
var point = fillSettings.ColorPoints[0]; | |
AssertIsTrue(point.MedianPointLocation == 50); | |
AssertIsTrue(point.Color == Color.FromArgb(9, 0, 178)); | |
AssertIsTrue(point.Location == 0); | |
point = fillSettings.ColorPoints[1]; | |
AssertIsTrue(point.MedianPointLocation == 50); | |
AssertIsTrue(point.Color == Color.Red); | |
AssertIsTrue(point.Location == 2048); | |
point = fillSettings.ColorPoints[2]; | |
AssertIsTrue(point.MedianPointLocation == 50); | |
AssertIsTrue(point.Color == Color.FromArgb(255, 252, 0)); | |
AssertIsTrue(point.Location == 3000); | |
point = fillSettings.ColorPoints[3]; | |
AssertIsTrue(point.MedianPointLocation == 75); | |
AssertIsTrue(point.Color == Color.Green); | |
AssertIsTrue(point.Location == 4096); | |
// Check transparent points | |
AssertIsTrue(fillSettings.TransparencyPoints.Length == 3); | |
var transparencyPoint = fillSettings.TransparencyPoints[0]; | |
AssertIsTrue(transparencyPoint.MedianPointLocation == 50); | |
AssertIsTrue(transparencyPoint.Opacity == 100); | |
AssertIsTrue(transparencyPoint.Location == 0); | |
transparencyPoint = fillSettings.TransparencyPoints[1]; | |
AssertIsTrue(transparencyPoint.MedianPointLocation == 50); | |
AssertIsTrue(transparencyPoint.Opacity == 100); | |
AssertIsTrue(transparencyPoint.Location == 2315); | |
transparencyPoint = fillSettings.TransparencyPoints[2]; | |
AssertIsTrue(transparencyPoint.MedianPointLocation == 25); | |
AssertIsTrue(transparencyPoint.Opacity == 25); | |
AssertIsTrue(transparencyPoint.Location == 4096); | |
} | |
catch (Exception e) | |
{ | |
string ex = e.StackTrace; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Make ability to add the newly generated regular layer to PsdImage | |
string sourceFileName = dataDir + "OneLayer.psd"; | |
string exportPath = dataDir + "OneLayerEdited.psd"; | |
string exportPathPng = dataDir + "OneLayerEdited.png"; | |
using (var im = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
// Preparing two int arrays | |
var data1 = new int[2500]; | |
var data2 = new int[2500]; | |
var rect1 = new Rectangle(0, 0, 50, 50); | |
var rect2 = new Rectangle(0, 0, 100, 25); | |
for (int i = 0; i < 2500; i++) | |
{ | |
data1[i] = -10000000; | |
data2[i] = -10000000; | |
} | |
var layer1 = im.AddRegularLayer(); | |
layer1.Left = 25; | |
layer1.Top = 25; | |
layer1.Right = 75; | |
layer1.Bottom = 75; | |
layer1.SaveArgb32Pixels(rect1, data1); | |
var layer2 = im.AddRegularLayer(); | |
layer2.Left = 25; | |
layer2.Top = 150; | |
layer2.Right = 125; | |
layer2.Bottom = 175; | |
layer2.SaveArgb32Pixels(rect2, data2); | |
// Save psd | |
im.Save(exportPath, new PsdOptions()); | |
// Save png | |
im.Save(exportPathPng, new PngOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Pattern overlay effect. Example | |
string sourceFileName = dataDir + "PatternOverlay.psd"; | |
string exportPath = dataDir + "PatternOverlayChanged.psd"; | |
var newPattern = new int[] | |
{ | |
Color.Aqua.ToArgb(), Color.Red.ToArgb(), Color.Red.ToArgb(), Color.Aqua.ToArgb(), | |
Color.Aqua.ToArgb(), Color.White.ToArgb(), Color.White.ToArgb(), Color.Aqua.ToArgb(), | |
}; | |
var newPatternBounds = new Rectangle(0, 0, 4, 2); | |
var guid = Guid.NewGuid(); | |
var newPatternName = "$$$/Presets/Patterns/Pattern=Some new pattern name\0"; | |
var loadOptions = new PsdLoadOptions() | |
{ | |
LoadEffectsResource = true | |
}; | |
using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) | |
{ | |
var patternOverlay = (PatternOverlayEffect)im.Layers[1].BlendingOptions.Effects[0]; | |
if ((patternOverlay.BlendMode != BlendMode.Normal) || | |
(patternOverlay.Opacity != 127) || | |
(patternOverlay.IsVisible != true) | |
) | |
{ | |
throw new Exception("Pattern overlay effect properties were read wrong"); | |
} | |
var settings = patternOverlay.Settings; | |
if ((settings.Color != Color.Empty) || | |
(settings.FillType != FillType.Pattern) || | |
(settings.PatternId != "85163837-eb9e-5b43-86fb-e6d5963ea29a\0") || | |
(settings.PatternName != "$$$/Presets/Patterns/OpticalSquares=Optical Squares\0") || | |
(settings.PointType != null) || | |
(Math.Abs(settings.Scale - 100) > 0.001) || | |
(settings.Linked != true) || | |
(Math.Abs(0 - settings.HorizontalOffset) > 0.001) || | |
(Math.Abs(0 - settings.VerticalOffset) > 0.001)) | |
{ | |
throw new Exception("Pattern overlay effect settings were read wrong"); | |
} | |
// Test editing | |
settings.Color = Color.Green; | |
patternOverlay.Opacity = 193; | |
patternOverlay.BlendMode = BlendMode.Difference; | |
settings.HorizontalOffset = 15; | |
settings.VerticalOffset = 11; | |
PattResource resource; | |
foreach (var globalLayerResource in im.GlobalLayerResources) | |
{ | |
if (globalLayerResource is PattResource) | |
{ | |
resource = (PattResource)globalLayerResource; | |
resource.PatternId = guid.ToString(); | |
resource.Name = newPatternName; | |
resource.SetPattern(newPattern, newPatternBounds); | |
} | |
} | |
settings.PatternName = newPatternName; | |
settings.PatternId = guid.ToString() + "\0"; | |
im.Save(exportPath); | |
} | |
// Test file after edit | |
using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) | |
{ | |
var patternOverlay = (PatternOverlayEffect)im.Layers[1].BlendingOptions.Effects[0]; | |
try | |
{ | |
if ((patternOverlay.BlendMode != BlendMode.Difference) || | |
(patternOverlay.Opacity != 193) || | |
(patternOverlay.IsVisible != true)) | |
{ | |
throw new Exception("Pattern overlay effect properties were read wrong"); | |
} | |
var fillSettings = patternOverlay.Settings; | |
if ((fillSettings.Color != Color.Empty) || | |
(fillSettings.FillType != FillType.Pattern)) | |
{ | |
throw new Exception("Pattern overlay effect settings were read wrong"); | |
} | |
PattResource resource = null; | |
foreach (var globalLayerResource in im.GlobalLayerResources) | |
{ | |
if (globalLayerResource is PattResource) | |
{ | |
resource = (PattResource)globalLayerResource; | |
} | |
} | |
if (resource == null) | |
{ | |
throw new Exception("PattResource not found"); | |
} | |
// Check the pattern data | |
if ((resource.PatternData != newPattern) || | |
(newPatternBounds != new Rectangle(0, 0, resource.Width, resource.Height)) || | |
(resource.PatternId != guid.ToString()) || | |
(resource.Name != newPatternName) | |
) | |
{ | |
throw new Exception("Pattern was set wrong"); | |
} | |
} | |
catch (Exception e) | |
{ | |
string ex = e.StackTrace; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Create an instance of Image and load the primary image | |
using (Image canvas = Image.Load(dataDir + "layers.psd")) | |
{ | |
// Create another instance of Image and load the secondary image containing the signature graphics | |
using (Image signature = Image.Load(dataDir + "sample.psd")) | |
{ | |
// Create an instance of Graphics class and initialize it using the object of the primary image | |
Graphics graphics = new Graphics(canvas); | |
// Call the DrawImage method while passing the instance of secondary image and appropriate location. The following snippet tries to draw the secondary image at the right bottom of the primary image | |
graphics.DrawImage(signature, new Point(canvas.Height - signature.Height, canvas.Width - signature.Width)); | |
canvas.Save(dataDir + "AddSignatureToImage_out.png", new PngOptions()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Stroke effect. FillType - Color. Example | |
string sourceFileName = dataDir + "Stroke.psd"; | |
string exportPath = dataDir + "StrokeGradientChanged.psd"; | |
var loadOptions = new PsdLoadOptions() | |
{ | |
LoadEffectsResource = true | |
}; | |
using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) | |
{ | |
var colorStroke = (StrokeEffect)im.Layers[1].BlendingOptions.Effects[0]; | |
if ((colorStroke.BlendMode != BlendMode.Normal) || | |
(colorStroke.Opacity != 255) || | |
(colorStroke.IsVisible != true)) | |
{ | |
throw new Exception("Color stroke effect was read wrong"); | |
} | |
var fillSettings = (ColorFillSettings)colorStroke.FillSettings; | |
if ((fillSettings.Color != Color.Black) || (fillSettings.FillType != FillType.Color)) | |
{ | |
throw new Exception("Color stroke effect settings were read wrong"); | |
} | |
fillSettings.Color = Color.Yellow; | |
colorStroke.Opacity = 127; | |
colorStroke.BlendMode = BlendMode.Color; | |
im.Save(exportPath); | |
} | |
// Test file after edit | |
using (var im = (PsdImage)Image.Load(exportPath, loadOptions)) | |
{ | |
var colorStroke = (StrokeEffect)im.Layers[1].BlendingOptions.Effects[0]; | |
if ((colorStroke.BlendMode != BlendMode.Color) || | |
(colorStroke.Opacity != 127) || | |
(colorStroke.IsVisible != true)) | |
{ | |
throw new Exception("Color stroke effect was read wrong"); | |
} | |
var fillSettings = (ColorFillSettings)colorStroke.FillSettings; | |
if ((fillSettings.Color != Color.Yellow) || (fillSettings.FillType != FillType.Color)) | |
{ | |
throw new Exception("Color stroke effect settings were read wrong"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Stroke effect. FillType - Gradient. Example | |
void AssertIsTrue(bool condition, string message = "Assertion fails") | |
{ | |
if (!condition) | |
{ | |
throw new FormatException(message); | |
} | |
} | |
string sourceFileName = dataDir + "Stroke.psd"; | |
string exportPath = dataDir + "StrokeGradientChanged.psd"; | |
var loadOptions = new PsdLoadOptions() | |
{ | |
LoadEffectsResource = true | |
}; | |
using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) | |
{ | |
var gradientStroke = (StrokeEffect)im.Layers[2].BlendingOptions.Effects[0]; | |
AssertIsTrue(gradientStroke.BlendMode == BlendMode.Normal); | |
AssertIsTrue(gradientStroke.Opacity == 255); | |
AssertIsTrue(gradientStroke.IsVisible); | |
var fillSettings = (GradientFillSettings)gradientStroke.FillSettings; | |
AssertIsTrue(fillSettings.Color == Color.Black); | |
AssertIsTrue(fillSettings.FillType == FillType.Gradient); | |
AssertIsTrue(fillSettings.AlignWithLayer); | |
AssertIsTrue(fillSettings.GradientType == GradientType.Linear); | |
AssertIsTrue(Math.Abs(90 - fillSettings.Angle) < 0.001, "Angle is incorrect"); | |
AssertIsTrue(fillSettings.Dither == false); | |
AssertIsTrue(Math.Abs(0 - fillSettings.HorizontalOffset) < 0.001, "Horizontal offset is incorrect"); | |
AssertIsTrue(Math.Abs(0 - fillSettings.VerticalOffset) < 0.001, "Vertical offset is incorrect"); | |
AssertIsTrue(fillSettings.Reverse == false); | |
// Color Points | |
var colorPoints = fillSettings.ColorPoints; | |
AssertIsTrue(colorPoints.Length == 2); | |
AssertIsTrue(colorPoints[0].Color == Color.Black); | |
AssertIsTrue(colorPoints[0].Location == 0); | |
AssertIsTrue(colorPoints[0].MedianPointLocation == 50); | |
AssertIsTrue(colorPoints[1].Color == Color.White); | |
AssertIsTrue(colorPoints[1].Location == 4096); | |
AssertIsTrue(colorPoints[1].MedianPointLocation == 50); | |
// Transparency points | |
var transparencyPoints = fillSettings.TransparencyPoints; | |
AssertIsTrue(transparencyPoints.Length == 2); | |
AssertIsTrue(transparencyPoints[0].Location == 0); | |
AssertIsTrue(transparencyPoints[0].MedianPointLocation == 50); | |
AssertIsTrue(transparencyPoints[0].Opacity == 100); | |
AssertIsTrue(transparencyPoints[1].Location == 4096); | |
AssertIsTrue(transparencyPoints[1].MedianPointLocation == 50); | |
AssertIsTrue(transparencyPoints[1].Opacity == 100); | |
// Test editing | |
fillSettings.Color = Color.Green; | |
gradientStroke.Opacity = 127; | |
gradientStroke.BlendMode = BlendMode.Color; | |
fillSettings.AlignWithLayer = false; | |
fillSettings.GradientType = GradientType.Radial; | |
fillSettings.Angle = 45; | |
fillSettings.Dither = true; | |
fillSettings.HorizontalOffset = 15; | |
fillSettings.VerticalOffset = 11; | |
fillSettings.Reverse = true; | |
// Add new color point | |
var colorPoint = fillSettings.AddColorPoint(); | |
colorPoint.Color = Color.Green; | |
colorPoint.Location = 4096; | |
colorPoint.MedianPointLocation = 75; | |
// Change location of previous point | |
fillSettings.ColorPoints[1].Location = 1899; | |
// Add new transparency point | |
var transparencyPoint = fillSettings.AddTransparencyPoint(); | |
transparencyPoint.Opacity = 25; | |
transparencyPoint.MedianPointLocation = 25; | |
transparencyPoint.Location = 4096; | |
// Change location of previous transparency point | |
fillSettings.TransparencyPoints[1].Location = 2411; | |
im.Save(exportPath); | |
} | |
// Test file after edit | |
using (var im = (PsdImage)Image.Load(exportPath, loadOptions)) | |
{ | |
var gradientStroke = (StrokeEffect)im.Layers[2].BlendingOptions.Effects[0]; | |
if ((gradientStroke.BlendMode != BlendMode.Color) || | |
(gradientStroke.Opacity != 127) || | |
(gradientStroke.IsVisible != true)) | |
{ | |
throw new Exception("Assertion of Gradient Stroke fails"); | |
} | |
var fillSettings = (GradientFillSettings)gradientStroke.FillSettings; | |
if ((fillSettings.Color != Color.Green) || | |
(fillSettings.FillType != FillType.Gradient) || | |
fillSettings.ColorPoints.Length != 3) | |
{ | |
throw new Exception("Assertion fails"); | |
} | |
// Check color points | |
var point = fillSettings.ColorPoints[0]; | |
AssertIsTrue(point.MedianPointLocation == 50); | |
AssertIsTrue(point.Color == Color.Black); | |
AssertIsTrue(point.Location == 0); | |
point = fillSettings.ColorPoints[1]; | |
AssertIsTrue(point.MedianPointLocation == 50); | |
AssertIsTrue(point.Color == Color.White); | |
AssertIsTrue(point.Location == 1899); | |
point = fillSettings.ColorPoints[2]; | |
AssertIsTrue(point.MedianPointLocation == 75); | |
AssertIsTrue(point.Color == Color.Green); | |
AssertIsTrue(point.Location == 4096); | |
// Check transparent points | |
AssertIsTrue(fillSettings.TransparencyPoints.Length == 3); | |
var transparencyPoint = fillSettings.TransparencyPoints[0]; | |
AssertIsTrue(transparencyPoint.MedianPointLocation == 50); | |
AssertIsTrue(transparencyPoint.Opacity == 100); | |
AssertIsTrue(transparencyPoint.Location == 0); | |
transparencyPoint = fillSettings.TransparencyPoints[1]; | |
AssertIsTrue(transparencyPoint.MedianPointLocation == 50); | |
AssertIsTrue(transparencyPoint.Opacity == 100); | |
AssertIsTrue(transparencyPoint.Location == 2411); | |
transparencyPoint = fillSettings.TransparencyPoints[2]; | |
AssertIsTrue(transparencyPoint.MedianPointLocation == 25); | |
AssertIsTrue(transparencyPoint.Opacity == 25); | |
AssertIsTrue(transparencyPoint.Location == 4096); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Stroke effect. FillType - Pattern. Example | |
string sourceFileName = dataDir + "Stroke.psd"; | |
string exportPath = dataDir + "StrokePatternChanged.psd"; | |
var loadOptions = new PsdLoadOptions() | |
{ | |
LoadEffectsResource = true | |
}; | |
// Preparing new data | |
var newPattern = new int[] | |
{ | |
Color.Aqua.ToArgb(), Color.Red.ToArgb(), Color.Red.ToArgb(), Color.Aqua.ToArgb(), | |
Color.Aqua.ToArgb(), Color.White.ToArgb(), Color.White.ToArgb(), Color.Aqua.ToArgb(), | |
Color.Aqua.ToArgb(), Color.White.ToArgb(), Color.White.ToArgb(), Color.Aqua.ToArgb(), | |
Color.Aqua.ToArgb(), Color.Red.ToArgb(), Color.Red.ToArgb(), Color.Aqua.ToArgb(), | |
}; | |
var newPatternBounds = new Rectangle(0, 0, 4, 4); | |
var guid = Guid.NewGuid(); | |
using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) | |
{ | |
var patternStroke = (StrokeEffect)im.Layers[3].BlendingOptions.Effects[0]; | |
var fillSettings = (PatternFillSettings)patternStroke.FillSettings; | |
if ((patternStroke.BlendMode != BlendMode.Normal) || | |
(patternStroke.Opacity != 255) || | |
(patternStroke.IsVisible != true) || | |
(fillSettings.FillType != FillType.Pattern)) | |
{ | |
throw new Exception("Pattern effect properties were read wrong"); | |
} | |
patternStroke.Opacity = 127; | |
patternStroke.BlendMode = BlendMode.Color; | |
PattResource resource; | |
foreach (var globalLayerResource in im.GlobalLayerResources) | |
{ | |
if (globalLayerResource is PattResource) | |
{ | |
resource = (PattResource)globalLayerResource; | |
resource.PatternId = guid.ToString(); | |
resource.Name = "$$$/Presets/Patterns/HorizontalLine1=Horizontal Line 9\0"; | |
resource.SetPattern(newPattern, newPatternBounds); | |
} | |
} | |
((PatternFillSettings)patternStroke.FillSettings).PatternName = "$$$/Presets/Patterns/HorizontalLine1=Horizontal Line 9\0"; | |
((PatternFillSettings)patternStroke.FillSettings).PatternId = guid.ToString() + "\0"; | |
im.Save(exportPath); | |
} | |
// Test file after edit | |
using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) | |
{ | |
var patternStroke = (StrokeEffect)im.Layers[3].BlendingOptions.Effects[0]; | |
PattResource resource = null; | |
foreach (var globalLayerResource in im.GlobalLayerResources) | |
{ | |
if (globalLayerResource is PattResource) | |
{ | |
resource = (PattResource)globalLayerResource; | |
} | |
} | |
if (resource == null) | |
{ | |
throw new Exception("PattResource not found"); | |
} | |
try | |
{ | |
// Check the pattern data | |
var fillSettings = (PatternFillSettings)patternStroke.FillSettings; | |
if ((resource.PatternData != newPattern) || | |
(newPatternBounds != new Rectangle(0, 0, resource.Width, resource.Height)) || | |
(resource.PatternId != guid.ToString()) || | |
(patternStroke.BlendMode != BlendMode.Color) || | |
(patternStroke.Opacity != 127) || | |
(patternStroke.IsVisible != true) || | |
(fillSettings.FillType != FillType.Pattern)) | |
{ | |
throw new Exception("Pattern stroke effect properties were read wrong"); | |
} | |
} | |
catch (Exception e) | |
{ | |
string ex = e.StackTrace; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string loadpath = dataDir + "sample.psd"; | |
string outpath = dataDir + "CoreDrawingFeatures.bmp"; | |
// Create an instance of Image | |
using (PsdImage image = new PsdImage(loadpath)) | |
{ | |
// load pixels | |
var pixels = image.LoadArgb32Pixels(new Rectangle(0, 0, 100, 10)); | |
for (int i = 0; i < pixels.Length; i++) | |
{ | |
// specify pixel color value (gradient in this case). | |
pixels[i] = i; | |
} | |
// save modified pixels. | |
image.SaveArgb32Pixels(new Rectangle(0, 0, 100, 10), pixels); | |
// export image to bmp file format. | |
image.Save(outpath, new BmpOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string outpath = dataDir + "Arc.bmp"; | |
// Create an instance of BmpOptions and set its various properties | |
BmpOptions saveOptions = new BmpOptions(); | |
saveOptions.BitsPerPixel = 32; | |
// Create an instance of Image | |
using (Image image = new PsdImage(100, 100)) | |
{ | |
// Create and initialize an instance of Graphics class and clear Graphics surface | |
Graphics graphic = new Graphics(image); | |
graphic.Clear(Color.Yellow); | |
// Draw an arc shape by specifying the Pen object having red black color and coordinates, height, width, start & end angles | |
int width = 100; | |
int height = 200; | |
int startAngle = 45; | |
int sweepAngle = 270; | |
// Draw arc to screen and save all changes. | |
graphic.DrawArc(new Pen(Color.Black), 0, 0, width, height, startAngle, sweepAngle); | |
// export image to bmp file format. | |
image.Save(outpath, saveOptions); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string outpath = dataDir + "Bezier.bmp"; | |
// Create an instance of BmpOptions and set its various properties | |
BmpOptions saveOptions = new BmpOptions(); | |
saveOptions.BitsPerPixel = 32; | |
// Create an instance of Image | |
using (Image image = new PsdImage(100, 100)) | |
{ | |
// Create and initialize an instance of Graphics class and clear Graphics surface | |
Graphics graphic = new Graphics(image); | |
graphic.Clear(Color.Yellow); | |
// Initializes the instance of PEN class with black color and width | |
Pen BlackPen = new Pen(Color.Black, 3); | |
float startX = 10; | |
float startY = 25; | |
float controlX1 = 20; | |
float controlY1 = 5; | |
float controlX2 = 55; | |
float controlY2 = 10; | |
float endX = 90; | |
float endY = 25; | |
// Draw a Bezier shape by specifying the Pen object having black color and co-ordinate Points and save all changes. | |
graphic.DrawBezier(BlackPen, startX, startY, controlX1, controlY1, controlX2, controlY2, endX, endY); | |
// export image to bmp file format. | |
image.Save(outpath, saveOptions); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string outpath = dataDir + "Ellipse.bmp"; | |
// Create an instance of BmpOptions and set its various properties | |
BmpOptions saveOptions = new BmpOptions(); | |
saveOptions.BitsPerPixel = 32; | |
// Create an instance of Image | |
using (Image image = new PsdImage(100, 100)) | |
{ | |
// Create and initialize an instance of Graphics class and Clear Graphics surface | |
Graphics graphic = new Graphics(image); | |
graphic.Clear(Color.Yellow); | |
// Draw a dotted ellipse shape by specifying the Pen object having red color and a surrounding Rectangle | |
graphic.DrawEllipse(new Pen(Color.Red), new Rectangle(30, 10, 40, 80)); | |
// Draw a continuous ellipse shape by specifying the Pen object having solid brush with blue color and a surrounding Rectangle | |
graphic.DrawEllipse(new Pen(new SolidBrush(Color.Blue)), new Rectangle(10, 30, 80, 40)); | |
// export image to bmp file format. | |
image.Save(outpath, saveOptions); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string outpath = dataDir + "Lines.bmp"; | |
BmpOptions saveOptions = new BmpOptions(); | |
saveOptions.BitsPerPixel = 32; | |
// Create an instance of Image | |
using (Image image = new PsdImage(100, 100)) | |
{ | |
// Create and initialize an instance of Graphics class and Clear Graphics surface | |
Graphics graphic = new Graphics(image); | |
graphic.Clear(Color.Yellow); | |
// Draw two dotted diagonal lines by specifying the Pen object having blue color and co-ordinate Points | |
graphic.DrawLine(new Pen(Color.Blue), 9, 9, 90, 90); | |
graphic.DrawLine(new Pen(Color.Blue), 9, 90, 90, 9); | |
// Draw a four continuous line by specifying the Pen object having Solid Brush with red color and two point structures | |
graphic.DrawLine(new Pen(new SolidBrush(Color.Red)), new Point(9, 9), new Point(9, 90)); | |
graphic.DrawLine(new Pen(new SolidBrush(Color.Aqua)), new Point(9, 90), new Point(90, 90)); | |
graphic.DrawLine(new Pen(new SolidBrush(Color.Black)), new Point(90, 90), new Point(90, 9)); | |
graphic.DrawLine(new Pen(new SolidBrush(Color.White)), new Point(90, 9), new Point(9, 9)); | |
image.Save(outpath, saveOptions); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string outpath = dataDir + "Rectangle.bmp"; | |
// Create an instance of BmpOptions and set its various properties | |
BmpOptions saveOptions = new BmpOptions(); | |
saveOptions.BitsPerPixel = 32; | |
// Create an instance of Image | |
using (Image image = new PsdImage(100, 100)) | |
{ | |
// Create and initialize an instance of Graphics class, Clear Graphics surface, Draw a rectangle shapes and save all changes. | |
Graphics graphic = new Graphics(image); | |
graphic.Clear(Color.Yellow); | |
graphic.DrawRectangle(new Pen(Color.Red), new Rectangle(30, 10, 40, 80)); | |
graphic.DrawRectangle(new Pen(new SolidBrush(Color.Blue)), new Rectangle(10, 30, 80, 40)); | |
// export image to bmp file format. | |
image.Save(outpath, saveOptions); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Create an instance of Image | |
using (PsdImage image = new PsdImage(500, 500)) | |
{ | |
var graphics = new Graphics(image); | |
// Clear the image surface with white color and Create and initialize a Pen object with blue color | |
graphics.Clear(Color.White); | |
var pen = new Pen(Color.Blue); | |
// Draw Ellipse by defining the bounding rectangle of width 150 and height 100 also Draw a polygon using the LinearGradientBrush | |
graphics.DrawEllipse(pen, new Rectangle(10, 10, 150, 100)); | |
using (var linearGradientBrush = new LinearGradientBrush(image.Bounds, Color.Red, Color.White, 45f)) | |
{ | |
graphics.FillPolygon(linearGradientBrush, new[] { new Point(200, 200), new Point(400, 200), new Point(250, 350) }); | |
} | |
// export modified image. | |
image.Save(dataDir + "DrawingUsingGraphics_output.bmp", new BmpOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Create an instance of Image and initialize an instance of Graphics | |
using (PsdImage image = new PsdImage(500, 500)) | |
{ | |
// create graphics surface. | |
Graphics graphics = new Graphics(image); | |
graphics.Clear(Color.White); | |
// Create an instance of GraphicsPath and Instance of Figure, add EllipseShape, RectangleShape and TextShape to the figure | |
GraphicsPath graphicspath = new GraphicsPath(); | |
Figure figure = new Figure(); | |
figure.AddShape(new EllipseShape(new RectangleF(0, 0, 499, 499))); | |
figure.AddShape(new RectangleShape(new RectangleF(0, 0, 499, 499))); | |
figure.AddShape(new TextShape("Aspose.PSD", new RectangleF(170, 225, 170, 100), new Font("Arial", 20), StringFormat.GenericTypographic)); | |
graphicspath.AddFigures(new[] { figure }); | |
graphics.DrawPath(new Pen(Color.Blue), graphicspath); | |
// Create an instance of HatchBrush and set its properties also Fill path by supplying the brush and GraphicsPath objects | |
HatchBrush hatchbrush = new HatchBrush(); | |
hatchbrush.BackgroundColor = Color.Brown; | |
hatchbrush.ForegroundColor = Color.Blue; | |
hatchbrush.HatchStyle = HatchStyle.Vertical; | |
graphics.FillPath(hatchbrush, graphicspath); | |
image.Save(dataDir + "DrawingUsingGraphicsPath_output.psd"); | |
Console.WriteLine("Processing completed successfully."); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string outputFilePath = "output.psd"; | |
using (var image = new PsdImage(100, 100)) | |
{ | |
FillLayer colorFillLayer = FillLayer.CreateInstance(FillType.Color); | |
colorFillLayer.DisplayName = "Color Fill Layer"; | |
image.AddLayer(colorFillLayer); | |
FillLayer gradientFillLayer = FillLayer.CreateInstance(FillType.Gradient); | |
gradientFillLayer.DisplayName = "Gradient Fill Layer"; | |
image.AddLayer(gradientFillLayer); | |
FillLayer patternFillLayer = FillLayer.CreateInstance(FillType.Pattern); | |
patternFillLayer.DisplayName = "Pattern Fill Layer"; | |
patternFillLayer.Opacity = 50; | |
image.AddLayer(patternFillLayer); | |
image.Save(outputFilePath); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFilePath = "BackgroundColorResourceInput.psd"; | |
string outputFilePath = "BackgroundColorResourceOutput.psd"; | |
using (var image = (PsdImage)Image.Load(sourceFilePath)) | |
{ | |
ResourceBlock[] imageResources = image.ImageResources; | |
BackgroundColorResource backgroundColorResource = null; | |
foreach (var imageResource in imageResources) | |
{ | |
if (imageResource is BackgroundColorResource) | |
{ | |
backgroundColorResource = (BackgroundColorResource)imageResource; | |
break; | |
} | |
} | |
// update BackgroundColorResource | |
backgroundColorResource.Color = Color.DarkRed; | |
image.Save(outputFilePath); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFilePath = "BorderInformationResourceInput.psd"; | |
string outputFilePath = "BorderInformationResourceOutput.psd"; | |
using (var image = (PsdImage)Image.Load(sourceFilePath)) | |
{ | |
ResourceBlock[] imageResources = image.ImageResources; | |
BorderInformationResource borderInfoResource = null; | |
foreach (var imageResource in imageResources) | |
{ | |
if (imageResource is BorderInformationResource) | |
{ | |
borderInfoResource = (BorderInformationResource)imageResource; | |
break; | |
} | |
} | |
// update BorderInformationResource | |
borderInfoResource.Width = 0.1; | |
borderInfoResource.Unit = PhysicalUnit.Inches; | |
image.Save(outputFilePath); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = "WorkingPathResourceInput.psd"; | |
string outputFile = "WorkingPathResourceOutput.psd"; | |
// Crop image and save. | |
using (var psdImage = (PsdImage)Image.Load(sourceFile)) | |
{ | |
// Search WorkingPathResource resource. | |
ResourceBlock[] imageResources = psdImage.ImageResources; | |
WorkingPathResource workingPathResource = null; | |
foreach (var imageResource in imageResources) | |
{ | |
if (imageResource is WorkingPathResource) | |
{ | |
workingPathResource = (WorkingPathResource)imageResource; | |
break; | |
} | |
} | |
BezierKnotRecord record = workingPathResource.Paths[3] as BezierKnotRecord; | |
if (record.Points[0].X != 2572506 || record.Points[0].Y != 8535408) | |
{ | |
throw new Exception("Values is incorrect."); | |
} | |
// Crop and save. | |
psdImage.Crop(0, 500, 0, 200); | |
psdImage.Save(outputFile); | |
} | |
// Load saved image and check the changes. | |
using (var psdImage = (PsdImage)Image.Load(outputFile)) | |
{ | |
// Search WorkingPathResource resource. | |
ResourceBlock[] imageResources = psdImage.ImageResources; | |
WorkingPathResource workingPathResource = null; | |
foreach (var imageResource in imageResources) | |
{ | |
if (imageResource is WorkingPathResource) | |
{ | |
workingPathResource = (WorkingPathResource)imageResource; | |
break; | |
} | |
} | |
BezierKnotRecord record = workingPathResource.Paths[3] as BezierKnotRecord; | |
if (record.Points[0].X != 4630510 || record.Points[0].Y != 22761088) | |
{ | |
throw new Exception("Values is incorrect."); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string srcFile = "AddStrokeEffect.psd"; | |
string outputFilePng = "AddStrokeEffect.png"; | |
using (var psdImage = (PsdImage)Image.Load(srcFile, new PsdLoadOptions() { LoadEffectsResource = true })) | |
{ | |
StrokeEffect strokeEffect; | |
IColorFillSettings colorFillSettings; | |
IGradientFillSettings gradientFillSettings; | |
IPatternFillSettings patternFillSettings; | |
// 1. Adds Color fill, at position Inside | |
strokeEffect = psdImage.Layers[1].BlendingOptions.AddStroke(FillType.Color); | |
strokeEffect.Size = 7; | |
strokeEffect.Position = StrokePosition.Inside; | |
colorFillSettings = strokeEffect.FillSettings as IColorFillSettings; | |
colorFillSettings.Color = Color.Green; | |
// 2. Adds Color fill, at position Outside | |
strokeEffect = psdImage.Layers[2].BlendingOptions.AddStroke(FillType.Color); | |
strokeEffect.Size = 7; | |
strokeEffect.Position = StrokePosition.Outside; | |
colorFillSettings = strokeEffect.FillSettings as IColorFillSettings; | |
colorFillSettings.Color = Color.Green; | |
// 3. Adds Color fill, at position Center | |
strokeEffect = psdImage.Layers[3].BlendingOptions.AddStroke(FillType.Color); | |
strokeEffect.Size = 7; | |
strokeEffect.Position = StrokePosition.Center; | |
colorFillSettings = strokeEffect.FillSettings as IColorFillSettings; | |
colorFillSettings.Color = Color.Green; | |
// 4. Adds Gradient fill, at position Inside | |
strokeEffect = psdImage.Layers[4].BlendingOptions.AddStroke(FillType.Gradient); | |
strokeEffect.Size = 5; | |
strokeEffect.Position = StrokePosition.Inside; | |
gradientFillSettings = strokeEffect.FillSettings as IGradientFillSettings; | |
gradientFillSettings.AlignWithLayer = false; | |
gradientFillSettings.Angle = 90; | |
// 5. Adds Gradient fill, at position Outside | |
strokeEffect = psdImage.Layers[5].BlendingOptions.AddStroke(FillType.Gradient); | |
strokeEffect.Size = 5; | |
strokeEffect.Position = StrokePosition.Outside; | |
gradientFillSettings = strokeEffect.FillSettings as IGradientFillSettings; | |
gradientFillSettings.AlignWithLayer = true; | |
gradientFillSettings.Angle = 90; | |
// 6. Adds Gradient fill, at position Center | |
strokeEffect = psdImage.Layers[6].BlendingOptions.AddStroke(FillType.Gradient); | |
strokeEffect.Size = 5; | |
strokeEffect.Position = StrokePosition.Center; | |
gradientFillSettings = strokeEffect.FillSettings as IGradientFillSettings; | |
gradientFillSettings.AlignWithLayer = true; | |
gradientFillSettings.Angle = 0; | |
// 7. Adds Pattern fill, at position Inside | |
strokeEffect = psdImage.Layers[7].BlendingOptions.AddStroke(FillType.Pattern); | |
strokeEffect.Size = 5; | |
strokeEffect.Position = StrokePosition.Inside; | |
patternFillSettings = strokeEffect.FillSettings as IPatternFillSettings; | |
patternFillSettings.Scale = 200; | |
// 8. Adds Pattern fill, at position Outside | |
strokeEffect = psdImage.Layers[8].BlendingOptions.AddStroke(FillType.Pattern); | |
strokeEffect.Size = 10; | |
strokeEffect.Position = StrokePosition.Outside; | |
patternFillSettings = strokeEffect.FillSettings as IPatternFillSettings; | |
patternFillSettings.Scale = 100; | |
// 9. Adds Pattern fill, at position Center | |
strokeEffect = psdImage.Layers[9].BlendingOptions.AddStroke(FillType.Pattern); | |
strokeEffect.Size = 10; | |
strokeEffect.Position = StrokePosition.Center; | |
patternFillSettings = strokeEffect.FillSettings as IPatternFillSettings; | |
patternFillSettings.Scale = 75; | |
psdImage.Save(outputFilePng, new PngOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFilePath = "gradientOverlayEffect.psd"; | |
string outputFilePath = "output"; | |
string outputPng = outputFilePath + ".png"; | |
string outputPsd = outputFilePath + ".psd"; | |
using (var psdImage = (PsdImage)Image.Load(sourceFilePath, new PsdLoadOptions() { LoadEffectsResource = true })) | |
{ | |
psdImage.Save(outputPng, new PngOptions()); | |
psdImage.Save(outputPsd); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFilePath = "psdnet256.psd"; | |
string outputFilePath = "psdnet256.psd_output.psd"; | |
// Creates/Gets and edits the gradient overlay effect in a layer. | |
using (var psdImage = (PsdImage)Image.Load(sourceFilePath, new PsdLoadOptions() { LoadEffectsResource = true })) | |
{ | |
BlendingOptions layerBlendOptions = psdImage.Layers[1].BlendingOptions; | |
GradientOverlayEffect gradientOverlayEffect = null; | |
// Search GradientOverlayEffect in a layer. | |
foreach (ILayerEffect effect in layerBlendOptions.Effects) | |
{ | |
gradientOverlayEffect = effect as GradientOverlayEffect; | |
if (gradientOverlayEffect != null) | |
{ | |
break; | |
} | |
} | |
if (gradientOverlayEffect == null) | |
{ | |
// You can create a new GradientOverlayEffect if it not exists. | |
gradientOverlayEffect = layerBlendOptions.AddGradientOverlay(); | |
} | |
// Add a bit of transparency to the effect. | |
gradientOverlayEffect.Opacity = 200; | |
// Change the blend mode of gradient effect. | |
gradientOverlayEffect.BlendMode = BlendMode.Hue; | |
// Gets GradientFillSettings object to configure gradient overlay settings. | |
GradientFillSettings settings = gradientOverlayEffect.Settings; | |
// Setting a new gradient with two colors. | |
settings.ColorPoints = new IGradientColorPoint[] | |
{ | |
new GradientColorPoint(Color.GreenYellow, 0, 50), | |
new GradientColorPoint(Color.BlueViolet, 4096, 50), | |
}; | |
// Sets an inclination of the gradient at an angle of 80 degrees. | |
settings.Angle = 80; | |
// Scale gradient effect up to 150%. | |
settings.Scale = 150; | |
// Sets type of gradient. | |
settings.GradientType = GradientType.Linear; | |
// Make the gradient opaque by setting the opacity to 100% at each transparency point. | |
settings.TransparencyPoints[0].Opacity = 100; | |
settings.TransparencyPoints[1].Opacity = 100; | |
psdImage.Save(outputFilePath); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
void AssertIsTrue(bool condition, string message) | |
{ | |
if (!condition) | |
{ | |
throw new FormatException(message); | |
} | |
} | |
void ExampleSupportOfBlwhResource( | |
string sourceFileName, | |
int reds, | |
int yellows, | |
int greens, | |
int cyans, | |
int blues, | |
int magentas, | |
bool useTint, | |
int bwPresetKind, | |
string bwPresetFileName, | |
double tintColorRed, | |
double tintColorGreen, | |
double tintColorBlue, | |
int tintColor, | |
int newTintColor) | |
{ | |
string destinationFileName = OutputDir + "Output_" + sourceFileName; | |
bool isRequiredResourceFound = false; | |
using (PsdImage im = (PsdImage)Image.Load(SourceDir + sourceFileName)) | |
{ | |
foreach (var layer in im.Layers) | |
{ | |
foreach (var layerResource in layer.Resources) | |
{ | |
if (layerResource is BlwhResource) | |
{ | |
var blwhResource = (BlwhResource)layerResource; | |
var blwhLayer = (BlackWhiteAdjustmentLayer)layer; | |
isRequiredResourceFound = true; | |
AssertIsTrue(blwhResource.Reds == reds, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(blwhResource.Yellows == yellows, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(blwhResource.Greens == greens, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(blwhResource.Cyans == cyans, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(blwhResource.Blues == blues, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(blwhResource.Magentas == magentas, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(blwhResource.UseTint == useTint, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(blwhResource.TintColor == tintColor, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(blwhResource.BwPresetKind == bwPresetKind, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(blwhResource.BlackAndWhitePresetFileName == bwPresetFileName, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(Math.Abs(blwhLayer.TintColorRed - tintColorRed) < 1e-6, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(Math.Abs(blwhLayer.TintColorGreen - tintColorGreen) < 1e-6, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(Math.Abs(blwhLayer.TintColorBlue - tintColorBlue) < 1e-6, ActualPropertyValueIsWrongMessage); | |
// Test editing and saving | |
blwhResource.Reds = reds - 15; | |
blwhResource.Yellows = yellows - 15; | |
blwhResource.Greens = greens + 15; | |
blwhResource.Cyans = cyans + 15; | |
blwhResource.Blues = blues - 15; | |
blwhResource.Magentas = magentas - 15; | |
blwhResource.UseTint = !useTint; | |
blwhResource.BwPresetKind = 4; | |
blwhResource.BlackAndWhitePresetFileName = "bwPresetFileName"; | |
blwhLayer.TintColorRed = tintColorRed - 60; | |
blwhLayer.TintColorGreen = tintColorGreen - 60; | |
blwhLayer.TintColorBlue = tintColorBlue - 60; | |
im.Save(destinationFileName); | |
break; | |
} | |
} | |
} | |
} | |
AssertIsTrue(isRequiredResourceFound, "The specified BlwhResource not found"); | |
isRequiredResourceFound = false; | |
using (PsdImage im = (PsdImage)Image.Load(destinationFileName)) | |
{ | |
foreach (var layer in im.Layers) | |
{ | |
foreach (var layerResource in layer.Resources) | |
{ | |
if (layerResource is BlwhResource) | |
{ | |
var blwhResource = (BlwhResource)layerResource; | |
var blwhLayer = (BlackWhiteAdjustmentLayer)layer; | |
isRequiredResourceFound = true; | |
AssertIsTrue(blwhResource.Reds == reds - 15, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(blwhResource.Yellows == yellows - 15, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(blwhResource.Greens == greens + 15, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(blwhResource.Cyans == cyans + 15, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(blwhResource.Blues == blues - 15, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(blwhResource.Magentas == magentas - 15, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(blwhResource.UseTint == !useTint, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(blwhResource.TintColor == newTintColor, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(blwhResource.BwPresetKind == 4, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(blwhResource.BlackAndWhitePresetFileName == "bwPresetFileName", ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(Math.Abs(blwhLayer.TintColorRed - tintColorRed + 60) < 1e-6, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(Math.Abs(blwhLayer.TintColorGreen - tintColorGreen + 60) < 1e-6, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(Math.Abs(blwhLayer.TintColorBlue - tintColorBlue + 60) < 1e-6, ActualPropertyValueIsWrongMessage); | |
break; | |
} | |
} | |
} | |
} | |
AssertIsTrue(isRequiredResourceFound, "The specified BlwhResource not found"); | |
} | |
ExampleSupportOfBlwhResource( | |
"BlackWhiteAdjustmentLayerStripesMask.psd", | |
0x28, | |
0x3c, | |
0x28, | |
0x3c, | |
0x14, | |
0x50, | |
false, | |
1, | |
"\0", | |
225.00045776367188, | |
211.00067138671875, | |
179.00115966796875, | |
-1977421, | |
-5925001); | |
ExampleSupportOfBlwhResource( | |
"BlackWhiteAdjustmentLayerStripesMask2.psd", | |
0x80, | |
0x40, | |
0x20, | |
0x10, | |
0x08, | |
0x04, | |
true, | |
4, | |
"\0", | |
239.996337890625, | |
127.998046875, | |
63.9990234375, | |
-1015744, | |
-4963324); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string destinationFileName = OutputDir + "SampleForClblResource_out.psd"; | |
ClblResource GetClblResource(PsdImage psdImage) | |
{ | |
foreach (var layer in psdImage.Layers) | |
{ | |
foreach (var layerResource in layer.Resources) | |
{ | |
if (layerResource is ClblResource) | |
{ | |
return (ClblResource)layerResource; | |
} | |
} | |
} | |
throw new Exception("The specified ClblResource not found"); | |
} | |
using (PsdImage psdImage = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
var resource = GetClblResource(psdImage); | |
Console.WriteLine("ClblResource.BlendClippedElements [should be true]: " + resource.BlendClippedElements); | |
// Test editing and saving | |
resource.BlendClippedElements = false; | |
psdImage.Save(destinationFileName); | |
} | |
using (PsdImage psdImage = (PsdImage)Image.Load(destinationFileName)) | |
{ | |
var resource = GetClblResource(psdImage); | |
Console.WriteLine("ClblResource.BlendClippedElements [should change to false]: " + resource.BlendClippedElements); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
{ | |
if (!condition) | |
{ | |
throw new FormatException(message); | |
} | |
} | |
string sourceFileName = SourceDir + "SampleForInfxResource.psd"; | |
string destinationFileName = OutputDir + "SampleForInfxResource_out.psd"; | |
bool isRequiredResourceFound = false; | |
using (PsdImage im = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
foreach (var layer in im.Layers) | |
{ | |
foreach (var layerResource in layer.Resources) | |
{ | |
if (layerResource is InfxResource) | |
{ | |
var resource = (InfxResource)layerResource; | |
isRequiredResourceFound = true; | |
AssertIsTrue(!resource.BlendInteriorElements, "The InfxResource.BlendInteriorElements should be false"); | |
// Test editing and saving | |
resource.BlendInteriorElements = true; | |
im.Save(destinationFileName); | |
break; | |
} | |
} | |
} | |
} | |
AssertIsTrue(isRequiredResourceFound, "The specified InfxResource not found"); | |
isRequiredResourceFound = false; | |
using (PsdImage im = (PsdImage)Image.Load(destinationFileName)) | |
{ | |
foreach (var layer in im.Layers) | |
{ | |
foreach (var layerResource in layer.Resources) | |
{ | |
if (layerResource is InfxResource) | |
{ | |
var resource = (InfxResource)layerResource; | |
isRequiredResourceFound = true; | |
AssertIsTrue(resource.BlendInteriorElements, "The InfxResource.BlendInteriorElements should change to true"); | |
break; | |
} | |
} | |
} | |
} | |
AssertIsTrue(isRequiredResourceFound, "The specified InfxResource not found"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
void AssertIsTrue(bool condition, string message) | |
{ | |
if (!condition) | |
{ | |
throw new FormatException(message); | |
} | |
} | |
string sourceFileName = SourceDir + "SampleForLspfResource.psd"; | |
string destinationFileName = OutputDir + "SampleForLspfResource_out.psd"; | |
bool isRequiredResourceFound = false; | |
using (PsdImage im = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
foreach (var layer in im.Layers) | |
{ | |
foreach (var layerResource in layer.Resources) | |
{ | |
if (layerResource is LspfResource) | |
{ | |
var resource = (LspfResource)layerResource; | |
isRequiredResourceFound = true; | |
AssertIsTrue(false == resource.IsCompositeProtected, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(false == resource.IsPositionProtected, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(false == resource.IsTransparencyProtected, ActualPropertyValueIsWrongMessage); | |
// Test editing and saving | |
resource.IsCompositeProtected = true; | |
AssertIsTrue(true == resource.IsCompositeProtected, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(false == resource.IsPositionProtected, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(false == resource.IsTransparencyProtected, ActualPropertyValueIsWrongMessage); | |
resource.IsCompositeProtected = false; | |
resource.IsPositionProtected = true; | |
AssertIsTrue(false == resource.IsCompositeProtected, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(true == resource.IsPositionProtected, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(false == resource.IsTransparencyProtected, ActualPropertyValueIsWrongMessage); | |
resource.IsPositionProtected = false; | |
resource.IsTransparencyProtected = true; | |
AssertIsTrue(false == resource.IsCompositeProtected, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(false == resource.IsPositionProtected, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(true == resource.IsTransparencyProtected, ActualPropertyValueIsWrongMessage); | |
resource.IsCompositeProtected = true; | |
resource.IsPositionProtected = true; | |
resource.IsTransparencyProtected = true; | |
im.Save(destinationFileName); | |
break; | |
} | |
} | |
} | |
} | |
AssertIsTrue(isRequiredResourceFound, "The specified LspfResource not found"); | |
isRequiredResourceFound = false; | |
using (PsdImage im = (PsdImage)Image.Load(destinationFileName)) | |
{ | |
foreach (var layer in im.Layers) | |
{ | |
foreach (var layerResource in layer.Resources) | |
{ | |
if (layerResource is LspfResource) | |
{ | |
var resource = (LspfResource)layerResource; | |
isRequiredResourceFound = true; | |
AssertIsTrue(resource.IsCompositeProtected, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(resource.IsPositionProtected, ActualPropertyValueIsWrongMessage); | |
AssertIsTrue(resource.IsTransparencyProtected, ActualPropertyValueIsWrongMessage); | |
break; | |
} | |
} | |
} | |
} | |
AssertIsTrue(isRequiredResourceFound, "The specified LspfResource not found"); | |
Console.WriteLine("LspfResource updating works as expected. Press any key."); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
This is a Low-Level Aspose.PSD API. You can use Brightness/Contrast Layer through its API, which will be much easier, | |
but direct PhotoShop resource editing gives you more control over the PSD file content. */ | |
string path = "BrightnessContrastPS6.psd"; | |
string outputPath = "BrightnessContrastPS6_output.psd"; | |
using (PsdImage im = (PsdImage)Image.Load(path)) | |
{ | |
foreach (var layer in im.Layers) | |
{ | |
if (layer is BrightnessContrastLayer) | |
{ | |
foreach (var layerResource in layer.Resources) | |
{ | |
if (layerResource is BritResource) | |
{ | |
var resource = (BritResource)layerResource; | |
if (resource.Brightness != -40 || | |
resource.Contrast != 10 || | |
resource.LabColor != false || | |
resource.MeanValueForBrightnessAndContrast != 127) | |
{ | |
throw new Exception("BritResource was read wrong"); | |
} | |
// Test editing and saving | |
resource.Brightness = 25; | |
resource.Contrast = -14; | |
resource.LabColor = true; | |
resource.MeanValueForBrightnessAndContrast = 200; | |
im.Save(outputPath, new PsdOptions()); | |
break; | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFilePath = "AllLclrResourceColors.psd"; | |
string outputFilePath = "AllLclrResourceColorsReversed.psd"; | |
// In the file colors of layers' highlighting are in this order | |
SheetColorHighlightEnum[] sheetColorsArr = new SheetColorHighlightEnum[] { | |
SheetColorHighlightEnum.Red, | |
SheetColorHighlightEnum.Orange, | |
SheetColorHighlightEnum.Yellow, | |
SheetColorHighlightEnum.Green, | |
SheetColorHighlightEnum.Blue, | |
SheetColorHighlightEnum.Violet, | |
SheetColorHighlightEnum.Gray, | |
SheetColorHighlightEnum.NoColor | |
}; | |
// Layer Sheet Color is used to visually highlight layers. | |
// For example you can update some layers in PSD and then highlight by color the layer which you want to attract attention. (Sheet color setting) | |
using (PsdImage img = (PsdImage)Image.Load(sourceFilePath)) | |
{ | |
CheckSheetColorsAndRerverse(sheetColorsArr, img); | |
img.Save(outputFilePath, new PsdOptions()); | |
} | |
using (PsdImage img = (PsdImage)Image.Load(outputFilePath)) | |
{ | |
// Colors should be reversed | |
Array.Reverse(sheetColorsArr); | |
CheckSheetColorsAndRerverse(sheetColorsArr, img); | |
} | |
void CheckSheetColorsAndRerverse(SheetColorHighlightEnum[] sheetColors, PsdImage img) | |
{ | |
int layersCount = img.Layers.Length; | |
for (int layerIndex = 0; layerIndex < layersCount; layerIndex++) | |
{ | |
Layer layer = img.Layers[layerIndex]; | |
LayerResource[] resources = layer.Resources; | |
foreach (LayerResource layerResource in resources) | |
{ | |
// The lcrl resource always presents in psd file resource list. | |
LclrResource resource = layerResource as LclrResource; | |
if (resource != null) | |
{ | |
if (resource.Color != sheetColors[layerIndex]) | |
{ | |
throw new Exception("Sheet Color has been read wrong"); | |
} | |
// Reverse of style sheet colors. Set up of Layer color highlight. | |
resource.Color = sheetColors[layersCount - layerIndex - 1]; | |
break; | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
void AssertAreEqual(object expected, object actual) | |
{ | |
if (!object.Equals(actual, expected)) | |
{ | |
throw new FormatException(string.Format("Actual value {0} are not equal to expected {1}.", actual, expected)); | |
} | |
} | |
object[] Lnk2ResourceSupportCases = new object[] | |
{ | |
new object[] | |
{ | |
"00af34a0-a90b-674d-a821-73ee508c5479", | |
"rgb8_2x2.png", | |
"png", | |
string.Empty, | |
0x53, | |
0d, | |
string.Empty, | |
7, | |
true, | |
0x124L, | |
0x74cL | |
} | |
}; | |
object[] LayeredLnk2ResourceSupportCases = new object[] | |
{ | |
new object[] | |
{ | |
"69ac1c0d-1b74-fd49-9c7e-34a7aa6299ef", | |
"huset.jpg", | |
"JPEG", | |
string.Empty, | |
0x9d46, | |
0d, | |
"xmp.did:0F94B342065B11E395B1FD506DED6B07", | |
7, | |
true, | |
0x9E60L, | |
0xc60cL | |
}, | |
new object[] | |
{ | |
"5a7d1965-0eae-b24e-a82f-98c7646424c2", | |
"panama-papers.jpg", | |
"JPEG", | |
string.Empty, | |
0xF56B, | |
0d, | |
"xmp.did:BDE940CBF51B11E59D759CDA690663E3", | |
7, | |
true, | |
0xF694L, | |
0x10dd4L | |
}, | |
}; | |
object[] LayeredLnk3ResourceSupportCases = new object[] | |
{ | |
new object[] | |
{ | |
"2fd7ba52-0221-de4c-bdc4-1210580c6caa", | |
"panama-papers.jpg", | |
"JPEG", | |
string.Empty, | |
0xF56B, | |
0d, | |
"xmp.did:BDE940CBF51B11E59D759CDA690663E3", | |
7, | |
true, | |
0xF694l, | |
0x10dd4L | |
}, | |
new object[] | |
{ | |
"372d52eb-5825-8743-81a7-b6f32d51323d", | |
"huset.jpg", | |
"JPEG", | |
string.Empty, | |
0x9d46, | |
0d, | |
"xmp.did:0F94B342065B11E395B1FD506DED6B07", | |
7, | |
true, | |
0x9E60L, | |
0xc60cL | |
}, | |
}; | |
var basePath = "" + "\\"; | |
// Saves the data of a smart object in PSD file to a file. | |
void SaveSmartObjectData(string prefix, string fileName, byte[] data) | |
{ | |
var filePath = prefix + "_" + fileName; | |
using (var container = FileStreamContainer.CreateFileStream(filePath, false)) | |
{ | |
container.Write(data); | |
} | |
} | |
// Loads the new data for a smart object in PSD file. | |
byte[] LoadNewData(string fileName) | |
{ | |
using (var container = FileStreamContainer.OpenFileStream(basePath + fileName)) | |
{ | |
return container.ToBytes(); | |
} | |
} | |
// Gets and sets properties of the PSD Lnk2 / Lnk3 Resource and its liFD data sources in PSD image | |
void ExampleOfLnk2ResourceSupport( | |
string fileName, | |
int dataSourceCount, | |
int length, | |
int newLength, | |
object[] dataSourceExpectedValues) | |
{ | |
using (PsdImage image = (PsdImage)Image.Load(basePath + fileName)) | |
{ | |
Lnk2Resource lnk2Resource = null; | |
foreach (var resource in image.GlobalLayerResources) | |
{ | |
lnk2Resource = resource as Lnk2Resource; | |
if (lnk2Resource != null) | |
{ | |
AssertAreEqual(lnk2Resource.DataSourceCount, dataSourceCount); | |
AssertAreEqual(lnk2Resource.Length, length); | |
AssertAreEqual(lnk2Resource.IsEmpty, false); | |
for (int i = 0; i < lnk2Resource.DataSourceCount; i++) | |
{ | |
LiFdDataSource lifdSource = lnk2Resource[i]; | |
object[] expected = (object[])dataSourceExpectedValues[i]; | |
AssertAreEqual(LinkDataSourceType.liFD, lifdSource.Type); | |
AssertAreEqual(new Guid((string)expected[0]), lifdSource.UniqueId); | |
AssertAreEqual(expected[1], lifdSource.OriginalFileName); | |
AssertAreEqual(expected[2], lifdSource.FileType.TrimEnd(' ')); | |
AssertAreEqual(expected[3], lifdSource.FileCreator.TrimEnd(' ')); | |
AssertAreEqual(expected[4], lifdSource.Data.Length); | |
AssertAreEqual(expected[5], lifdSource.AssetModTime); | |
AssertAreEqual(expected[6], lifdSource.ChildDocId); | |
AssertAreEqual(expected[7], lifdSource.Version); | |
AssertAreEqual((bool)expected[8], lifdSource.HasFileOpenDescriptor); | |
AssertAreEqual(expected[9], lifdSource.Length); | |
if (lifdSource.HasFileOpenDescriptor) | |
{ | |
AssertAreEqual(-1, lifdSource.CompId); | |
AssertAreEqual(-1, lifdSource.OriginalCompId); | |
lifdSource.CompId = int.MaxValue; | |
} | |
SaveSmartObjectData( | |
output + fileName, | |
lifdSource.OriginalFileName, | |
lifdSource.Data); | |
lifdSource.Data = LoadNewData("new_" + lifdSource.OriginalFileName); | |
AssertAreEqual(expected[10], lifdSource.Length); | |
lifdSource.ChildDocId = Guid.NewGuid().ToString(); | |
lifdSource.AssetModTime = double.MaxValue; | |
lifdSource.FileType = "test"; | |
lifdSource.FileCreator = "me"; | |
} | |
AssertAreEqual(newLength, lnk2Resource.Length); | |
break; | |
} | |
} | |
AssertAreEqual(true, lnk2Resource != null); | |
if (image.BitsPerChannel < 32) // 32 bit per channel saving is not supported yet | |
{ | |
image.Save(output + fileName, new PsdOptions(image)); | |
} | |
} | |
} | |
// This example demonstrates how to get and set properties of the PSD Lnk2 Resource and its liFD data sources for 8 bit per channel. | |
ExampleOfLnk2ResourceSupport("rgb8_2x2_embedded_png.psd", 1, 0x12C, 0x0000079c, Lnk2ResourceSupportCases); | |
// This example demonstrates how to get and set properties of the PSD Lnk3 Resource and its liFD data sources for 32 bit per channel. | |
ExampleOfLnk2ResourceSupport("Layered PSD file smart objects.psd", 2, 0x19504, 0x0001d3e0, LayeredLnk3ResourceSupportCases); | |
// This example demonstrates how to get and set properties of the PSD Lnk2 Resource and its liFD data sources for 16 bit per channel. | |
ExampleOfLnk2ResourceSupport("LayeredSmartObjects16bit.psd", 2, 0x19504, 0x0001d3e0, LayeredLnk2ResourceSupportCases); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string message = "The example works incorrectly."; | |
void AssertAreEqual(object actual, object expected) | |
{ | |
if (!object.Equals(actual, expected)) | |
{ | |
throw new FormatException(message); | |
} | |
} | |
// This example demonstrates how to get and set properties of the Psd LnkE Resource that contains information about an external linked file. | |
void ExampleOfLnkEResourceSupport( | |
string fileName, | |
int length, | |
int length2, | |
int length3, | |
int length4, | |
string fullPath, | |
string date, | |
double assetModTime, | |
string childDocId, | |
bool locked, | |
string uid, | |
string name, | |
string originalFileName, | |
string fileType, | |
long size, | |
int version) | |
{ | |
string outputPath = fileName; | |
using (PsdImage image = (PsdImage) Image.Load(fileName)) | |
{ | |
LnkeResource lnkeResource = null; | |
foreach (var resource in image.GlobalLayerResources) | |
{ | |
lnkeResource = resource as LnkeResource; | |
if (lnkeResource != null) | |
{ | |
LiFeDataSource lifeSource = lnkeResource[0]; | |
AssertAreEqual(lnkeResource.Length, length); | |
AssertAreEqual(lifeSource.UniqueId, new Guid(uid)); | |
AssertAreEqual(lifeSource.FullPath, fullPath); | |
AssertAreEqual(lifeSource.Date.ToString(CultureInfo.InvariantCulture), date); | |
AssertAreEqual(lifeSource.AssetModTime, assetModTime); | |
AssertAreEqual(lifeSource.FileName, name); | |
AssertAreEqual(lifeSource.FileSize, size); | |
AssertAreEqual(lifeSource.ChildDocId, childDocId); | |
AssertAreEqual(lifeSource.Version, version); | |
AssertAreEqual(lifeSource.FileType.TrimEnd(' '), fileType); | |
AssertAreEqual(lifeSource.FileCreator.TrimEnd(' '), string.Empty); | |
AssertAreEqual(lifeSource.OriginalFileName, originalFileName); | |
AssertAreEqual(false, lnkeResource.IsEmpty); | |
AssertAreEqual(true, lifeSource.Type == LinkDataSourceType.liFE); | |
if (version == 7) | |
{ | |
AssertAreEqual(lifeSource.AssetLockedState, locked); | |
} | |
if (lifeSource.HasFileOpenDescriptor) | |
{ | |
AssertAreEqual(lifeSource.CompId, -1); | |
AssertAreEqual(lifeSource.OriginalCompId, -1); | |
} | |
lifeSource.FullPath = | |
@"file:///C:/Aspose/net/Aspose.Psd/test/testdata/Images/Psd/SmartObjects/rgb8_2x2.png"; | |
AssertAreEqual(lnkeResource.Length, length2); | |
lifeSource.FileName = "rgb8_2x23.png"; | |
AssertAreEqual(lnkeResource.Length, length3); | |
lifeSource.ChildDocId = Guid.NewGuid().ToString(); | |
AssertAreEqual(lnkeResource.Length, length4); | |
lifeSource.Date = DateTime.Now; | |
lifeSource.AssetModTime = double.MaxValue; | |
lifeSource.FileSize = long.MaxValue; | |
lifeSource.FileType = "test"; | |
lifeSource.FileCreator = "file"; | |
lifeSource.CompId = int.MaxValue; | |
break; | |
} | |
} | |
AssertAreEqual(true, lnkeResource != null); | |
image.Save(outputPath, new PsdOptions(image)); | |
} | |
} | |
// This example demonstrates how to get and set properties of the Psd LnkeResource that contains information about external linked JPEG file. | |
ExampleOfLnkEResourceSupport( | |
@"photooverlay_5_new.psd", | |
0x21c, | |
0x26c, | |
0x274, | |
0x27c, | |
@"file:///C:/Users/cvallejo/Desktop/photo.jpg", | |
"05/09/2017 22:24:51", | |
0, | |
"F062B9DB73E8D124167A4186E54664B0", | |
false, | |
"02df245c-36a2-11e7-a9d8-fdb2b61f07a7", | |
"photo.jpg", | |
"photo.jpg", | |
"JPEG", | |
0x1520d, | |
7); | |
// This example demonstrates how to get and set properties of the PSD LnkeResource that contains information about an external linked PNG file. | |
ExampleOfLnkEResourceSupport( | |
"rgb8_2x2_linked.psd", | |
0x284, | |
0x290, | |
0x294, | |
0x2dc, | |
@"file:///C:/Aspose/net/Aspose.Psd/test/testdata/Issues/PSDNET-491/rgb8_2x2.png", | |
"04/14/2020 14:23:44", | |
0, | |
string.Empty, | |
false, | |
"5867318f-3174-9f41-abca-22f56a75247e", | |
"rgb8_2x2.png", | |
"rgb8_2x2.png", | |
"png", | |
0x53, | |
7); | |
// This example demonstrates how to get and set properties of the PSD LnkeResource that contains information about two external linked PNG and PSD files. | |
ExampleOfLnkEResourceSupport( | |
"rgb8_2x2_linked2.psd", | |
0x590, | |
0x580, | |
0x554, | |
0x528, | |
@"file:///C:/Aspose/net/Aspose.Psd/test/testdata/Images/Psd/AddColorBalanceAdjustmentLayer.psd", | |
"01/15/2020 13:02:00", | |
0, | |
"adobe:docid:photoshop:9312f484-3403-a644-8973-e725abc95fb7", | |
false, | |
"78a5b588-364f-0940-a2e5-a450a031aa48", | |
"AddColorBalanceAdjustmentLayer.psd", | |
"AddColorBalanceAdjustmentLayer.psd", | |
"8BPS", | |
0x4aea, | |
7); | |
// This example demonstrates how to get and set properties of the Photoshop Psd LnkeResource that contains information about an external linked CC Libraries Asset. | |
ExampleOfLnkEResourceSupport( | |
"rgb8_2x2_asset_linked.psd", | |
0x398, | |
0x38c, | |
0x388, | |
0x3d0, | |
@"CC Libraries Asset “rgb8_2x2_linked/rgb8_2x2” (Feature is available in Photoshop CC 2015)", | |
"01/01/0001 00:00:00", | |
1588890915488.0d, | |
string.Empty, | |
false, | |
"ec15f0a8-7f13-a640-b928-7d29c6e9859c", | |
"rgb8_2x2_linked", | |
"rgb8_2x2.png", | |
"png", | |
0, | |
7); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFilePath = "InvertAdjustmentLayer.psd"; | |
NvrtResource resource = null; | |
using (PsdImage psdImage = (PsdImage)Image.Load(sourceFilePath)) | |
{ | |
foreach (Layer layer in psdImage.Layers) | |
{ | |
if (layer is InvertAdjustmentLayer) | |
{ | |
foreach (LayerResource layerResource in layer.Resources) | |
{ | |
if (layerResource is NvrtResource) | |
{ | |
// The NvrtResource is supported. | |
resource = (NvrtResource)layerResource; | |
break; | |
} | |
} | |
} | |
} | |
} | |
if (resource is null) | |
{ | |
throw new Exception("NvrtResource Not Found"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
void AssertIsTrue(bool condition) | |
{ | |
if (!condition) | |
{ | |
throw new FormatException(string.Format("Expected true")); | |
} | |
} | |
void AssertAreEqual(object actual, object expected) | |
{ | |
var areEqual = object.Equals(actual, expected); | |
if (!areEqual && actual is Array && expected is Array) | |
{ | |
var actualArray = (Array)actual; | |
var expectedArray = (Array)actual; | |
if (actualArray.Length == expectedArray.Length) | |
{ | |
for (int i = 0; i < actualArray.Length; i++) | |
{ | |
if (!object.Equals(actualArray.GetValue(i), expectedArray.GetValue(i))) | |
{ | |
break; | |
} | |
} | |
areEqual = true; | |
} | |
} | |
if (!areEqual) | |
{ | |
throw new FormatException( | |
string.Format("Actual value {0} are not equal to expected {1}.", actual, expected)); | |
} | |
} | |
void CheckSmartObjectResourceValues(object[] expectedValue, SmartObjectResource resource) | |
{ | |
AssertAreEqual(expectedValue[0], resource.IsCustom); | |
AssertAreEqual(expectedValue[2], resource.PageNumber); | |
AssertAreEqual(expectedValue[3], resource.TotalPages); | |
AssertAreEqual(expectedValue[4], resource.AntiAliasPolicy); | |
AssertAreEqual(expectedValue[5], resource.PlacedLayerType); | |
AssertAreEqual(8, resource.TransformMatrix.Length); | |
AssertAreEqual((double[])expectedValue[6], resource.TransformMatrix); | |
AssertAreEqual(expectedValue[7], resource.Value); | |
AssertAreEqual(expectedValue[8], resource.Perspective); | |
AssertAreEqual(expectedValue[9], resource.PerspectiveOther); | |
AssertAreEqual(expectedValue[10], resource.Top); | |
AssertAreEqual(expectedValue[11], resource.Left); | |
AssertAreEqual(expectedValue[12], resource.Bottom); | |
AssertAreEqual(expectedValue[13], resource.Right); | |
AssertAreEqual(expectedValue[14], resource.UOrder); | |
AssertAreEqual(expectedValue[15], resource.VOrder); | |
AssertAreEqual(expectedValue[16], resource.Crop); | |
AssertAreEqual(expectedValue[17], resource.FrameStepNumerator); | |
AssertAreEqual(expectedValue[18], resource.FrameStepDenominator); | |
AssertAreEqual(expectedValue[19], resource.DurationNumerator); | |
AssertAreEqual(expectedValue[20], resource.DurationDenominator); | |
AssertAreEqual(expectedValue[21], resource.FrameCount); | |
AssertAreEqual(expectedValue[22], resource.Width); | |
AssertAreEqual(expectedValue[23], resource.Height); | |
AssertAreEqual(expectedValue[24], resource.Resolution); | |
AssertAreEqual(expectedValue[25], resource.ResolutionUnit); | |
AssertAreEqual(expectedValue[26], resource.Comp); | |
AssertAreEqual(expectedValue[27], resource.CompId); | |
AssertAreEqual(expectedValue[28], resource.OriginalCompId); | |
AssertAreEqual(expectedValue[29], resource.PlacedId.ToString()); | |
AssertAreEqual(expectedValue[30], resource.NonAffineTransformMatrix); | |
if (resource.IsCustom) | |
{ | |
AssertAreEqual(expectedValue[31], resource.HorizontalMeshPointUnit); | |
AssertAreEqual((double[])expectedValue[32], resource.HorizontalMeshPoints); | |
AssertAreEqual(expectedValue[33], resource.VerticalMeshPointUnit); | |
AssertAreEqual((double[])expectedValue[34], resource.VerticalMeshPoints); | |
} | |
} | |
void SetNewSmartValues(SmartObjectResource resource, object[] newValues) | |
{ | |
// This values we do not change in resource | |
newValues[0] = resource.IsCustom; | |
newValues[1] = resource.UniqueId.ToString(); | |
newValues[5] = resource.PlacedLayerType; | |
newValues[14] = resource.UOrder; | |
newValues[15] = resource.VOrder; | |
newValues[28] = resource.OriginalCompId; | |
// This values should be changed in the PlLdResource (with the specified UniqueId) as well | |
// and some of them must be in accord with the underlining smart object in the LinkDataSource | |
resource.PageNumber = (int)newValues[2]; // 2; | |
resource.TotalPages = (int)newValues[3]; // 3; | |
resource.AntiAliasPolicy = (int)newValues[4]; // 0; | |
resource.TransformMatrix = (double[])newValues[6]; | |
resource.Value = (double)newValues[7]; // 1.23456789; | |
resource.Perspective = (double)newValues[8]; // 0.123456789; | |
resource.PerspectiveOther = (double)newValues[9]; // 0.987654321; | |
resource.Top = (double)newValues[10]; // -126; | |
resource.Left = (double)newValues[11]; // -215; | |
resource.Bottom = (double)newValues[12]; // 248; | |
resource.Right = (double)newValues[13]; // 145; | |
resource.Crop = (int)newValues[16]; // 5; | |
resource.FrameStepNumerator = (int)newValues[17]; // 1; | |
resource.FrameStepDenominator = (int)newValues[18]; // 601; | |
resource.DurationNumerator = (int)newValues[19]; // 2; | |
resource.DurationDenominator = (int)newValues[20]; // 602; | |
resource.FrameCount = (int)newValues[21]; // 11; | |
resource.Width = (double)newValues[22]; // 541; | |
resource.Height = (double)newValues[23]; // 249; | |
resource.Resolution = (double)newValues[24]; // 144; | |
resource.ResolutionUnit = (UnitTypes)newValues[25]; | |
resource.Comp = (int)newValues[26]; // 21; | |
resource.CompId = (int)newValues[27]; // 22; | |
resource.NonAffineTransformMatrix = (double[])newValues[30]; | |
// This unique Id should be changed in references if any | |
resource.PlacedId = new Guid((string)newValues[29]); // "12345678-9abc-def0-9876-54321fecba98"); | |
if (resource.IsCustom) | |
{ | |
resource.HorizontalMeshPointUnit = (UnitTypes)newValues[31]; | |
resource.HorizontalMeshPoints = (double[])newValues[32]; | |
resource.VerticalMeshPointUnit = (UnitTypes)newValues[33]; | |
resource.VerticalMeshPoints = (double[])newValues[34]; | |
} | |
// Be careful with some parameters: the saved image may become unreadable by Adobe® Photoshop® | |
////resource.UOrder = 6; | |
////resource.VOrder = 9; | |
// Do no change this otherwise you won't be able to use free transform | |
// or change the underlining smart object to the vector type | |
////resource.PlacedLayerType = PlacedLayerType.Vector; | |
// There should be valid PlLdResource with this unique Id | |
////resource.UniqueId = new Guid("98765432-10fe-cba0-1234-56789abcdef0"); | |
} | |
object[] newSmartValues = new object[] | |
{ | |
true, | |
null, | |
2, | |
3, | |
0, | |
PlacedLayerType.ImageStack, | |
new double[8] | |
{ | |
12.937922786050663, | |
19.419959734187131, | |
2.85445817782261, | |
1.0540625423957124, | |
7.20861031651307, | |
14.634102808208553, | |
17.292074924741144, | |
4 | |
}, | |
1.23456789, | |
0.123456789, | |
0.987654321, | |
-126d, | |
-215d, | |
248d, | |
145d, | |
4, | |
4, | |
5, | |
1, | |
601, | |
2, | |
602, | |
11, | |
541d, | |
249d, | |
144d, | |
UnitTypes.Percent, | |
21, | |
22, | |
23, | |
"12345678-9abc-def0-9876-54321fecba98", | |
new double[8] | |
{ | |
129.937922786050663, | |
195.419959734187131, | |
26.85445817782261, | |
12.0540625423957124, | |
72.20861031651307, | |
147.634102808208553, | |
175.292074924741144, | |
42 | |
}, | |
UnitTypes.Points, | |
new double[16] | |
{ | |
0.01d, 103.33333333333433d, 206.66686666666666d, 310.02d, | |
0.20d, 103.33333333333533d, 206.69666666666666d, 310.03d, | |
30.06d, 103.33333333336333d, 206.66660666666666d, 310.04d, | |
04.05d, 103.33333333373333d, 206.66666166666666d, 310.05d | |
}, | |
UnitTypes.Distance, | |
new double[16] | |
{ | |
0.06d, 0.07d, 0.08d, 0.09d, | |
49.066666666666664d, 49.266666666666664d, 49.566666666666664d, 49.766666666666664d, | |
99.133333333333329d, 99.433333333333329d, 99.633333333333329d, 99.833333333333329d, | |
140, 141, 142, 143, | |
}, | |
}; | |
object[] expectedValues = new object[] | |
{ | |
new object[] | |
{ | |
false, | |
"5867318f-3174-9f41-abca-22f56a75247e", | |
1, | |
1, | |
0x10, | |
PlacedLayerType.Raster, | |
new double[8] | |
{ | |
0, 0, 2, 0, 2, 2, 0, 2 | |
}, | |
0d, | |
0d, | |
0d, | |
0d, | |
0d, | |
2d, | |
2d, | |
4, | |
4, | |
1, | |
0, | |
600, | |
0, | |
600, | |
1, | |
2d, | |
2d, | |
72d, | |
UnitTypes.Density, | |
-1, | |
-1, | |
-1, | |
"64b3997c-06e0-be40-a349-41acf397c897", | |
new double[8] | |
{ | |
0, 0, 2, 0, 2, 2, 0, 2 | |
}, | |
} | |
}; | |
var sourceFilePath = baseFolder + "rgb8_2x2_linked.psd"; | |
var outputPath = output + "rgb8_2x2_linked_output.psd"; | |
using (PsdImage image = (PsdImage)Image.Load(sourceFilePath)) | |
{ | |
SoLeResource soleResource = null; | |
int index = 0; | |
foreach (Layer imageLayer in image.Layers) | |
{ | |
foreach (var imageResource in imageLayer.Resources) | |
{ | |
var resource = imageResource as SoLeResource; | |
if (resource != null) | |
{ | |
soleResource = resource; | |
var expectedValue = (object[])expectedValues[index++]; | |
AssertAreEqual(expectedValue[1], resource.UniqueId.ToString()); | |
CheckSmartObjectResourceValues(expectedValue, resource); | |
SetNewSmartValues(resource, newSmartValues); | |
break; | |
} | |
} | |
} | |
AssertIsTrue(soleResource != null); | |
image.Save(outputPath, new PsdOptions(image)); | |
using (PsdImage savedImage = (PsdImage)Image.Load(outputPath)) | |
{ | |
foreach (Layer imageLayer in savedImage.Layers) | |
{ | |
foreach (var imageResource in imageLayer.Resources) | |
{ | |
var resource = imageResource as SoLeResource; | |
if (resource != null) | |
{ | |
CheckSmartObjectResourceValues(newSmartValues, resource); | |
break; | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
void AssertAreEqual(object actual, object expected) | |
{ | |
var areEqual = object.Equals(actual, expected); | |
if (!areEqual && actual is Array && expected is Array) | |
{ | |
var actualArray = (Array)actual; | |
var expectedArray = (Array)actual; | |
if (actualArray.Length == expectedArray.Length) | |
{ | |
for (int i = 0; i < actualArray.Length; i++) | |
{ | |
if (!object.Equals(actualArray.GetValue(i), expectedArray.GetValue(i))) | |
{ | |
break; | |
} | |
} | |
areEqual = true; | |
} | |
} | |
if (!areEqual) | |
{ | |
throw new FormatException( | |
string.Format("Actual value {0} are not equal to expected {1}.", actual, expected)); | |
} | |
} | |
var sourceFilePath = baseFolder + "LayeredSmartObjects8bit2.psd"; | |
var outputFilePath = output + "LayeredSmartObjects8bit2_output.psd"; | |
var expectedValues = new object[] | |
{ | |
new object[] | |
{ | |
true, | |
"76f05a3b-7523-5e42-a1bb-27f4735bffa0", | |
1, | |
1, | |
0x10, | |
PlacedLayerType.Raster, | |
new double[8] | |
{ | |
29.937922786050663, | |
95.419959734187131, | |
126.85445817782261, | |
1.0540625423957124, | |
172.20861031651307, | |
47.634102808208553, | |
75.292074924741144, | |
142 | |
}, | |
0d, | |
0d, | |
0d, | |
0d, | |
0d, | |
149d, | |
310d, | |
4, | |
4, | |
UnitTypes.Pixels, | |
new double[16] | |
{ | |
0.0d, 103.33333333333333d, 206.66666666666666d, 310.0d, | |
0.0d, 103.33333333333333d, 206.66666666666666d, 310.0d, | |
0.0d, 103.33333333333333d, 206.66666666666666d, 310.0d, | |
0.0d, 103.33333333333333d, 206.66666666666666d, 310.0d | |
}, | |
UnitTypes.Pixels, | |
new double[16] | |
{ | |
0.0d, 0.0d, 0.0d, 0.0d, | |
49.666666666666664d, 49.666666666666664d, 49.666666666666664d, 49.666666666666664d, | |
99.333333333333329d, 99.333333333333329d, 99.333333333333329d, 99.333333333333329d, | |
149, 149, 149, 149, | |
}, | |
}, | |
new object[] | |
{ | |
true, | |
"cf0477a8-8f92-ac4f-9462-f78e26234851", | |
1, | |
1, | |
0x10, | |
PlacedLayerType.Raster, | |
new double[8] | |
{ | |
37.900314592235681, | |
-0.32118219433001371, | |
185.94210608826535, | |
57.7076819802063, | |
153.32047433609358, | |
140.9311755779743, | |
5.2786828400639294, | |
82.902311403437977, | |
}, | |
0d, | |
0d, | |
0d, | |
0d, | |
0d, | |
721d, | |
1280d, | |
4, | |
4, | |
UnitTypes.Pixels, | |
new double[16] | |
{ | |
0.0, 426.66666666666663, 853.33333333333326, 1280, | |
0.0, 426.66666666666663, 853.33333333333326, 1280, | |
0.0, 426.66666666666663, 853.33333333333326, 1280, | |
0.0, 426.66666666666663, 853.33333333333326, 1280, | |
}, | |
UnitTypes.Pixels, | |
new double[16] | |
{ | |
0.0, 0.0, 0.0, 0.0, | |
240.33333333333331, 240.33333333333331, 240.33333333333331, 240.33333333333331, | |
480.66666666666663, 480.66666666666663, 480.66666666666663, 480.66666666666663, | |
721, 721, 721, 721, | |
}, | |
0, | |
0 | |
} | |
}; | |
using (PsdImage image = (PsdImage)Image.Load(sourceFilePath)) | |
{ | |
PlLdResource resource = null; | |
int index = 0; | |
foreach (Layer imageLayer in image.Layers) | |
{ | |
foreach (var imageResource in imageLayer.Resources) | |
{ | |
resource = imageResource as PlLdResource; | |
if (resource != null) | |
{ | |
var expectedValue = (object[])expectedValues[index++]; | |
AssertAreEqual(expectedValue[0], resource.IsCustom); | |
AssertAreEqual(expectedValue[1], resource.UniqueId.ToString()); | |
AssertAreEqual(expectedValue[2], resource.PageNumber); | |
AssertAreEqual(expectedValue[3], resource.TotalPages); | |
AssertAreEqual(expectedValue[4], resource.AntiAliasPolicy); | |
AssertAreEqual(expectedValue[5], resource.PlacedLayerType); | |
AssertAreEqual(8, resource.TransformMatrix.Length); | |
AssertAreEqual((double[])expectedValue[6], resource.TransformMatrix); | |
AssertAreEqual(expectedValue[7], resource.Value); | |
AssertAreEqual(expectedValue[8], resource.Perspective); | |
AssertAreEqual(expectedValue[9], resource.PerspectiveOther); | |
AssertAreEqual(expectedValue[10], resource.Top); | |
AssertAreEqual(expectedValue[11], resource.Left); | |
AssertAreEqual(expectedValue[12], resource.Bottom); | |
AssertAreEqual(expectedValue[13], resource.Right); | |
AssertAreEqual(expectedValue[14], resource.UOrder); | |
AssertAreEqual(expectedValue[15], resource.VOrder); | |
if (resource.IsCustom) | |
{ | |
AssertAreEqual(expectedValue[16], resource.HorizontalMeshPointUnit); | |
AssertAreEqual((double[])expectedValue[17], resource.HorizontalMeshPoints); | |
AssertAreEqual(expectedValue[18], resource.VerticalMeshPointUnit); | |
AssertAreEqual((double[])expectedValue[19], resource.VerticalMeshPoints); | |
var temp = resource.VerticalMeshPoints; | |
resource.VerticalMeshPoints = resource.HorizontalMeshPoints; | |
resource.HorizontalMeshPoints = temp; | |
} | |
resource.PageNumber = 2; | |
resource.TotalPages = 3; | |
resource.AntiAliasPolicy = 30; | |
resource.Value = 1.23456789; | |
resource.Perspective = 0.123456789; | |
resource.PerspectiveOther = 0.987654321; | |
resource.Top = -126; | |
resource.Left = -215; | |
resource.Bottom = 248; | |
resource.Right = 145; | |
// Be careful with some parameters: image may became unreadable by Adobe® Photoshop® | |
////resource.UOrder = 6; | |
////resource.VOrder = 9; | |
// Do no change this otherwise you won't be able to use free transform | |
// or change the underlining smart object to the vector type | |
////resource.PlacedLayerType = PlacedLayerType.Vector; | |
// There should be valid PlLdResource with this unique Id | |
////resource.UniqueId = new Guid("98765432-10fe-cba0-1234-56789abcdef0"); | |
break; | |
} | |
} | |
} | |
AssertAreEqual(true, resource != null); | |
image.Save(outputFilePath, new PsdOptions(image)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// This example shows how to get or set the smart object layer data properties of the PSD file. | |
void AssertAreEqual(object actual, object expected) | |
{ | |
var areEqual = object.Equals(actual, expected); | |
if (!areEqual && actual is Array && expected is Array) | |
{ | |
var actualArray = (Array)actual; | |
var expectedArray = (Array)actual; | |
if (actualArray.Length == expectedArray.Length) | |
{ | |
for (int i = 0; i < actualArray.Length; i++) | |
{ | |
if (!object.Equals(actualArray.GetValue(i), expectedArray.GetValue(i))) | |
{ | |
break; | |
} | |
} | |
areEqual = true; | |
} | |
} | |
if (!areEqual) | |
{ | |
throw new FormatException( | |
string.Format("Actual value {0} are not equal to expected {1}.", actual, expected)); | |
} | |
} | |
var sourceFilePath = baseFolder + "LayeredSmartObjects8bit2.psd"; | |
var outputFilePath = output + "LayeredSmartObjects8bit2_output.psd"; | |
var expectedValues = new object[] | |
{ | |
new object[] | |
{ | |
true, | |
"76f05a3b-7523-5e42-a1bb-27f4735bffa0", | |
1, | |
1, | |
0x10, | |
PlacedLayerType.Raster, | |
new double[8] | |
{ | |
29.937922786050663, | |
95.419959734187131, | |
126.85445817782261, | |
1.0540625423957124, | |
172.20861031651307, | |
47.634102808208553, | |
75.292074924741144, | |
142 | |
}, | |
0.0, | |
0.0, | |
0.0, | |
0d, | |
0d, | |
149d, | |
310d, | |
4, | |
4, | |
1, | |
0, | |
600, | |
0, | |
600, | |
1, | |
310d, | |
149d, | |
72d, | |
UnitTypes.Density, | |
-1, | |
-1, | |
-1, | |
"d3388655-19e4-9742-82f2-f553bb01046a", | |
new double[8] | |
{ | |
29.937922786050663, | |
95.419959734187131, | |
126.85445817782261, | |
1.0540625423957124, | |
172.20861031651307, | |
47.634102808208553, | |
75.292074924741144, | |
142 | |
}, | |
UnitTypes.Pixels, | |
new double[16] | |
{ | |
0.0d, 103.33333333333333d, 206.66666666666666d, 310.0d, | |
0.0d, 103.33333333333333d, 206.66666666666666d, 310.0d, | |
0.0d, 103.33333333333333d, 206.66666666666666d, 310.0d, | |
0.0d, 103.33333333333333d, 206.66666666666666d, 310.0d | |
}, | |
UnitTypes.Pixels, | |
new double[16] | |
{ | |
0.0d, 0.0d, 0.0d, 0.0d, | |
49.666666666666664d, 49.666666666666664d, 49.666666666666664d, 49.666666666666664d, | |
99.333333333333329d, 99.333333333333329d, 99.333333333333329d, 99.333333333333329d, | |
149, 149, 149, 149, | |
}, | |
}, | |
new object[] | |
{ | |
true, | |
"cf0477a8-8f92-ac4f-9462-f78e26234851", | |
1, | |
1, | |
0x10, | |
PlacedLayerType.Raster, | |
new double[8] | |
{ | |
37.900314592235681, | |
-0.32118219433001371, | |
185.94210608826535, | |
57.7076819802063, | |
153.32047433609358, | |
140.9311755779743, | |
5.2786828400639294, | |
82.902311403437977, | |
}, | |
0.0, | |
0.0, | |
0.0, | |
0d, | |
0d, | |
721d, | |
1280d, | |
4, | |
4, | |
1, | |
0, | |
600, | |
0, | |
600, | |
1, | |
1280d, | |
721d, | |
72d, | |
UnitTypes.Density, | |
-1, | |
-1, | |
-1, | |
"625cc4b9-2c5f-344f-8636-03caf2bd3489", | |
new double[8] | |
{ | |
37.900314592235681, | |
-0.32118219433001371, | |
185.94210608826535, | |
57.7076819802063, | |
153.32047433609358, | |
140.9311755779743, | |
5.2786828400639294, | |
82.902311403437977, | |
}, | |
UnitTypes.Pixels, | |
new double[16] | |
{ | |
0.0, 426.66666666666663, 853.33333333333326, 1280, | |
0.0, 426.66666666666663, 853.33333333333326, 1280, | |
0.0, 426.66666666666663, 853.33333333333326, 1280, | |
0.0, 426.66666666666663, 853.33333333333326, 1280, | |
}, | |
UnitTypes.Pixels, | |
new double[16] | |
{ | |
0.0, 0.0, 0.0, 0.0, | |
240.33333333333331, 240.33333333333331, 240.33333333333331, 240.33333333333331, | |
480.66666666666663, 480.66666666666663, 480.66666666666663, 480.66666666666663, | |
721, 721, 721, 721, | |
}, | |
0, | |
0 | |
} | |
}; | |
using (PsdImage image = (PsdImage)Image.Load(sourceFilePath)) | |
{ | |
SoLdResource resource = null; | |
int index = 0; | |
foreach (Layer imageLayer in image.Layers) | |
{ | |
foreach (var imageResource in imageLayer.Resources) | |
{ | |
resource = imageResource as SoLdResource; | |
if (resource != null) | |
{ | |
var expectedValue = (object[])expectedValues[index++]; | |
AssertAreEqual(expectedValue[0], resource.IsCustom); | |
AssertAreEqual(expectedValue[1], resource.UniqueId.ToString()); | |
AssertAreEqual(expectedValue[2], resource.PageNumber); | |
AssertAreEqual(expectedValue[3], resource.TotalPages); | |
AssertAreEqual(expectedValue[4], resource.AntiAliasPolicy); | |
AssertAreEqual(expectedValue[5], resource.PlacedLayerType); | |
AssertAreEqual(8, resource.TransformMatrix.Length); | |
AssertAreEqual((double[])expectedValue[6], resource.TransformMatrix); | |
AssertAreEqual(expectedValue[7], resource.Value); | |
AssertAreEqual(expectedValue[8], resource.Perspective); | |
AssertAreEqual(expectedValue[9], resource.PerspectiveOther); | |
AssertAreEqual(expectedValue[10], resource.Top); | |
AssertAreEqual(expectedValue[11], resource.Left); | |
AssertAreEqual(expectedValue[12], resource.Bottom); | |
AssertAreEqual(expectedValue[13], resource.Right); | |
AssertAreEqual(expectedValue[14], resource.UOrder); | |
AssertAreEqual(expectedValue[15], resource.VOrder); | |
AssertAreEqual(expectedValue[16], resource.Crop); | |
AssertAreEqual(expectedValue[17], resource.FrameStepNumerator); | |
AssertAreEqual(expectedValue[18], resource.FrameStepDenominator); | |
AssertAreEqual(expectedValue[19], resource.DurationNumerator); | |
AssertAreEqual(expectedValue[20], resource.DurationDenominator); | |
AssertAreEqual(expectedValue[21], resource.FrameCount); | |
AssertAreEqual(expectedValue[22], resource.Width); | |
AssertAreEqual(expectedValue[23], resource.Height); | |
AssertAreEqual(expectedValue[24], resource.Resolution); | |
AssertAreEqual(expectedValue[25], resource.ResolutionUnit); | |
AssertAreEqual(expectedValue[26], resource.Comp); | |
AssertAreEqual(expectedValue[27], resource.CompId); | |
AssertAreEqual(expectedValue[28], resource.OriginalCompId); | |
AssertAreEqual(expectedValue[29], resource.PlacedId.ToString()); | |
AssertAreEqual((IEnumerable)expectedValue[30], resource.NonAffineTransformMatrix); | |
if (resource.IsCustom) | |
{ | |
AssertAreEqual(expectedValue[31], resource.HorizontalMeshPointUnit); | |
AssertAreEqual((double[])expectedValue[32], resource.HorizontalMeshPoints); | |
AssertAreEqual(expectedValue[33], resource.VerticalMeshPointUnit); | |
AssertAreEqual((double[])expectedValue[34], resource.VerticalMeshPoints); | |
var temp = resource.VerticalMeshPoints; | |
resource.VerticalMeshPoints = resource.HorizontalMeshPoints; | |
resource.HorizontalMeshPoints = temp; | |
} | |
// This values should be changed in the PlLdResource (with the specified UniqueId) as well | |
// and some of them must be in accord with the underlining smart object in the LinkDataSource | |
resource.PageNumber = 2; | |
resource.TotalPages = 3; | |
resource.AntiAliasPolicy = 0; | |
resource.Value = 1.23456789; | |
resource.Perspective = 0.123456789; | |
resource.PerspectiveOther = 0.987654321; | |
resource.Top = -126; | |
resource.Left = -215; | |
resource.Bottom = 248; | |
resource.Right = 145; | |
resource.Crop = 4; | |
resource.FrameStepNumerator = 1; | |
resource.FrameStepDenominator = 601; | |
resource.DurationNumerator = 2; | |
resource.DurationDenominator = 602; | |
resource.FrameCount = 11; | |
resource.Width = 541; | |
resource.Height = 249; | |
resource.Resolution = 144; | |
resource.Comp = 21; | |
resource.CompId = 22; | |
resource.TransformMatrix = new double[8] | |
{ | |
12.937922786050663, | |
19.419959734187131, | |
2.85445817782261, | |
1.0540625423957124, | |
7.20861031651307, | |
14.634102808208553, | |
17.292074924741144, | |
4 | |
}; | |
resource.NonAffineTransformMatrix = new double[8] | |
{ | |
129.937922786050663, | |
195.419959734187131, | |
26.85445817782261, | |
12.0540625423957124, | |
72.20861031651307, | |
147.634102808208553, | |
175.292074924741144, | |
42 | |
}; | |
// This unique Id should be changed in references if any | |
resource.PlacedId = new Guid("12345678-9abc-def0-9876-54321fecba98"); | |
// Be careful with some parameters: image may became unreadable by Adobe® Photoshop® | |
////resource.UOrder = 6; | |
////resource.VOrder = 9; | |
// Do no change this otherwise you won't be able to use free transform | |
// or change the underlining smart object to the vector type | |
////resource.PlacedLayerType = PlacedLayerType.Vector; | |
// There should be valid PlLdResource with this unique Id | |
////resource.UniqueId = new Guid("98765432-10fe-cba0-1234-56789abcdef0"); | |
break; | |
} | |
} | |
} | |
AssertAreEqual(true, resource != null); | |
image.Save(outputFilePath, new PsdOptions(image)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
void ExampleOfVogkResourceSupport() | |
{ | |
// The path to the documents directory. | |
string SourceDir = RunExamples.GetDataDir_PSD(); | |
string OutputDir = RunExamples.GetDataDir_Output(); | |
string fileName = "VectorOriginationDataResource.psd"; | |
string outFileName = "out_VectorOriginationDataResource_.psd"; | |
using (var psdImage = (PsdImage)Image.Load(fileName)) | |
{ | |
var resource = GetVogkResource(psdImage); | |
// Reading | |
if (resource.ShapeOriginSettings.Length != 1 || | |
!resource.ShapeOriginSettings[0].IsShapeInvalidated || | |
resource.ShapeOriginSettings[0].OriginIndex != 0) | |
{ | |
throw new Exception("VogkResource were read wrong."); | |
} | |
// Editing | |
resource.ShapeOriginSettings = new[] | |
{ | |
resource.ShapeOriginSettings[0], | |
new VectorShapeOriginSettings(true, 1) | |
}; | |
psdImage.Save(outFileName); | |
} | |
} | |
VogkResource GetVogkResource(PsdImage image) | |
{ | |
var layer = image.Layers[1]; | |
VogkResource resource = null; | |
var resources = layer.Resources; | |
for (int i = 0; i < resources.Length; i++) | |
{ | |
if (resources[i] is VogkResource) | |
{ | |
resource = (VogkResource)resources[i]; | |
break; | |
} | |
} | |
if (resource == null) | |
{ | |
throw new Exception("VogkResourcenot found."); | |
} | |
return resource; | |
} | |
ExampleOfVogkResourceSupport(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// This example demonstrates that loading and saving the PSD image with shape layers and vector paths works correctly. | |
// The path to the documents directory. | |
string SourceDir = RunExamples.GetDataDir_PSD(); | |
string OutputDir = RunExamples.GetDataDir_Output(); | |
string sourcePath = "vectorShapes.psd"; | |
string outputFilePath = "output_vectorShapes.psd"; | |
using (PsdImage image = (PsdImage)Image.Load(sourcePath)) | |
{ | |
var resource = GetVogkResource(image); | |
AssertAreEqual(1, resource.ShapeOriginSettings.Length); | |
var setting = resource.ShapeOriginSettings[0]; | |
AssertAreEqual(true, setting.IsOriginIndexPresent); | |
AssertAreEqual(false, setting.IsShapeInvalidatedPresent); | |
AssertAreEqual(true, setting.IsOriginResolutionPresent); | |
AssertAreEqual(true, setting.IsOriginTypePresent); | |
AssertAreEqual(true, setting.IsOriginShapeBBoxPresent); | |
AssertAreEqual(false, setting.IsOriginRadiiRectanglePresent); | |
AssertAreEqual(0, setting.OriginIndex); | |
var originalSetting = resource.ShapeOriginSettings[0]; | |
originalSetting.IsShapeInvalidated = true; | |
resource.ShapeOriginSettings = new[] | |
{ | |
originalSetting, | |
new VectorShapeOriginSettings() | |
{ | |
OriginIndex = 1, | |
OriginResolution = 144, | |
OriginType = 4, | |
OriginShapeBox = new VectorShapeBoundingBox() | |
{ | |
Bounds = Rectangle.FromLeftTopRightBottom(10, 15, 40, 70) | |
} | |
}, | |
new VectorShapeOriginSettings() | |
{ | |
OriginIndex = 2, | |
OriginResolution = 301, | |
OriginType = 5, | |
OriginRadiiRectangle = new VectorShapeRadiiRectangle() | |
{ | |
TopLeft = 2, | |
TopRight = 6, | |
BottomLeft = 23, | |
BottomRight = 42, | |
QuadVersion = 1 | |
} | |
} | |
}; | |
image.Save(outputFilePath, new PsdOptions()); | |
} | |
using (PsdImage image = (PsdImage)Image.Load(outputFilePath)) | |
{ | |
var resource = GetVogkResource(image); | |
AssertAreEqual(3, resource.ShapeOriginSettings.Length); | |
var setting = resource.ShapeOriginSettings[0]; | |
AssertAreEqual(true, setting.IsOriginIndexPresent); | |
AssertAreEqual(true, setting.IsShapeInvalidatedPresent); | |
AssertAreEqual(true, setting.IsOriginResolutionPresent); | |
AssertAreEqual(true, setting.IsOriginTypePresent); | |
AssertAreEqual(true, setting.IsOriginShapeBBoxPresent); | |
AssertAreEqual(false, setting.IsOriginRadiiRectanglePresent); | |
AssertAreEqual(0, setting.OriginIndex); | |
AssertAreEqual(true, setting.IsShapeInvalidated); | |
setting = resource.ShapeOriginSettings[1]; | |
AssertAreEqual(true, setting.IsOriginIndexPresent); | |
AssertAreEqual(false, setting.IsShapeInvalidatedPresent); | |
AssertAreEqual(true, setting.IsOriginResolutionPresent); | |
AssertAreEqual(true, setting.IsOriginTypePresent); | |
AssertAreEqual(true, setting.IsOriginShapeBBoxPresent); | |
AssertAreEqual(false, setting.IsOriginRadiiRectanglePresent); | |
AssertAreEqual(1, setting.OriginIndex); | |
AssertAreEqual(144.0, setting.OriginResolution); | |
AssertAreEqual(4, setting.OriginType); | |
AssertAreEqual(Rectangle.FromLeftTopRightBottom(10, 15, 40, 70), setting.OriginShapeBox.Bounds); | |
setting = resource.ShapeOriginSettings[2]; | |
AssertAreEqual(true, setting.IsOriginIndexPresent); | |
AssertAreEqual(false, setting.IsShapeInvalidatedPresent); | |
AssertAreEqual(true, setting.IsOriginResolutionPresent); | |
AssertAreEqual(true, setting.IsOriginTypePresent); | |
AssertAreEqual(false, setting.IsOriginShapeBBoxPresent); | |
AssertAreEqual(true, setting.IsOriginRadiiRectanglePresent); | |
AssertAreEqual(2, setting.OriginIndex); | |
AssertAreEqual(301.0, setting.OriginResolution); | |
AssertAreEqual(5, setting.OriginType); | |
AssertAreEqual(2.0, setting.OriginRadiiRectangle.TopLeft); | |
AssertAreEqual(6.0, setting.OriginRadiiRectangle.TopRight); | |
AssertAreEqual(23.0, setting.OriginRadiiRectangle.BottomLeft); | |
AssertAreEqual(42.0, setting.OriginRadiiRectangle.BottomRight); | |
AssertAreEqual(1, setting.OriginRadiiRectangle.QuadVersion); | |
} | |
VogkResource GetVogkResource(PsdImage image) | |
{ | |
var layer = image.Layers[1]; | |
VogkResource resource = null; | |
var resources = layer.Resources; | |
for (int i = 0; i < resources.Length; i++) | |
{ | |
if (resources[i] is VogkResource) | |
{ | |
resource = (VogkResource)resources[i]; | |
break; | |
} | |
} | |
if (resource == null) | |
{ | |
throw new Exception("VogkResource not found."); | |
} | |
return resource; | |
} | |
void AssertAreEqual(object expected, object actual, string message = null) | |
{ | |
if (!object.Equals(expected, actual)) | |
{ | |
throw new FormatException(message ?? "Objects are not equal."); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string fileName = SourceDir + "PathOperationsShape.psd"; | |
string outFileName = OutputDir + "out_PathOperationsShape.psd"; | |
using (var im = (PsdImage)Image.Load(fileName)) | |
{ | |
VsmsResource resource = null; | |
foreach (var layerResource in im.Layers[1].Resources) | |
{ | |
if (layerResource is VsmsResource) | |
{ | |
resource = (VsmsResource)layerResource; | |
break; | |
} | |
} | |
LengthRecord lengthRecord0 = (LengthRecord)resource.Paths[2]; | |
LengthRecord lengthRecord1 = (LengthRecord)resource.Paths[7]; | |
LengthRecord lengthRecord2 = (LengthRecord)resource.Paths[11]; | |
// Here we changin the way to combining betwen shapes. | |
lengthRecord0.PathOperations = PathOperations.ExcludeOverlappingShapes; | |
lengthRecord1.PathOperations = PathOperations.IntersectShapeAreas; | |
lengthRecord2.PathOperations = PathOperations.SubtractFrontShape; | |
im.Save(outFileName); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Create an instance of CAD Metered class | |
Metered metered = new Metered(); | |
// Access the setMeteredKey property and pass public and private keys as parameters | |
metered.SetMeteredKey("*****", "*****"); | |
// Get metered data amount before calling API | |
decimal amountbefore = Metered.GetConsumptionQuantity(); | |
// Display information | |
Console.WriteLine("Amount Consumed Before: " + amountbefore.ToString()); | |
// Get metered data amount After calling API | |
decimal amountafter = Metered.GetConsumptionQuantity(); | |
// Display information | |
Console.WriteLine("Amount Consumed After: " + amountafter.ToString()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string[] sourcesFiles = new string[] | |
{ | |
@"34992OStroke", | |
@"rect2_color", | |
}; | |
for (int i = 0; i < sourcesFiles.Length; i++) | |
{ | |
string name = sourcesFiles[i]; | |
string sourceFileName = dataDir + name + ".ai"; | |
string outFileName = dataDir + name + ".gif"; | |
using (AiImage image = (AiImage)Image.Load(sourceFileName)) | |
{ | |
ImageOptionsBase options = new GifOptions() { DoPaletteCorrection = false }; | |
image.Save(outFileName, options); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
{ | |
@"34992OStroke", | |
@"rect2_color", | |
}; | |
for (int i = 0; i < sourcesFiles.Length; i++) | |
{ | |
string name = sourcesFiles[i]; | |
string sourceFileName = dataDir + name + ".ai"; | |
string outFileName = dataDir + name + ".jpg"; | |
using (AiImage image = (AiImage)Image.Load(sourceFileName)) | |
{ | |
ImageOptionsBase options = new JpegOptions() { Quality = 85 }; | |
image.Save(outFileName, options); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
{ | |
@"rect2_color", | |
}; | |
for (int i = 0; i < sourcesFiles.Length; i++) | |
{ | |
string name = sourcesFiles[i]; | |
string sourceFileName = dataDir + name + ".ai"; | |
string outFileName = dataDir + name + ".pdf"; | |
using (AiImage image = (AiImage)Image.Load(sourceFileName)) | |
{ | |
ImageOptionsBase options = new PdfOptions(); | |
image.Save(outFileName, options); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string[] sourcesFiles = new string[] | |
{ | |
@"34992OStroke", | |
@"rect2_color", | |
}; | |
for (int i = 0; i < sourcesFiles.Length; i++) | |
{ | |
string name = sourcesFiles[i]; | |
string sourceFileName = dataDir + name + ".ai"; | |
string outFileName = dataDir + name + ".png"; | |
using (AiImage image = (AiImage)Image.Load(sourceFileName)) | |
{ | |
ImageOptionsBase options = new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }; | |
image.Save(outFileName, options); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
{ | |
@"34992OStroke", | |
@"rect2_color", | |
}; | |
for (int i = 0; i < sourcesFiles.Length; i++) | |
{ | |
string name = sourcesFiles[i]; | |
string sourceFileName = dataDir + name + ".ai"; | |
string outFileName = dataDir + name + ".psd"; | |
using (AiImage image = (AiImage)Image.Load(sourceFileName)) | |
{ | |
ImageOptionsBase options = new PsdOptions(); | |
image.Save(outFileName, options); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string[] sourcesFiles = new string[] | |
{ | |
@"34992OStroke", | |
@"rect2_color", | |
}; | |
for (int i = 0; i < sourcesFiles.Length; i++) | |
{ | |
string name = sourcesFiles[i]; | |
string sourceFileName = dataDir + name + ".ai"; | |
string outFileName = dataDir + name + ".tif"; | |
using (AiImage image = (AiImage)Image.Load(sourceFileName)) | |
{ | |
ImageOptionsBase options = new TiffOptions(TiffExpectedFormat.TiffDeflateRgba); | |
image.Save(outFileName, options); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFileName = dataDir + "form_8.ai"; | |
string outputFileName = dataDir + "form_8_export"; | |
using (AiImage image = (AiImage)Image.Load(sourceFileName)) | |
{ | |
image.Save(outputFileName + ".psd", new PsdOptions()); | |
image.Save(outputFileName + ".png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
void AssertIsTrue(bool condition, string message) | |
{ | |
if (!condition) | |
{ | |
throw new FormatException(message); | |
} | |
} | |
string sourceFile = dataDir + "sample.ai"; | |
using (AiImage image = (AiImage)Image.Load(sourceFile)) | |
{ | |
AiLayerSection layer = image.Layers[0]; | |
AssertIsTrue(layer.RasterImages != null, "RasterImages property should be not null"); | |
AssertIsTrue(layer.RasterImages.Length == 1, "RasterImages property should contain exactly one item"); | |
AiRasterImageSection rasterImage = layer.RasterImages[0]; | |
AssertIsTrue(rasterImage.Pixels != null, "rasterImage.Pixels property should be not null"); | |
AssertIsTrue(rasterImage.Pixels.Length == 100, "rasterImage.Pixels property should contain exactly 100 items"); | |
AssertIsTrue((uint)rasterImage.Pixels[99] == 0xFFB21616, "rasterImage.Pixels[99] should be 0xFFB21616"); | |
AssertIsTrue((uint)rasterImage.Pixels[19] == 0xFF00FF00, "rasterImage.Pixels[19] should be 0xFF00FF00"); | |
AssertIsTrue((uint)rasterImage.Pixels[10] == 0xFF01FD00, "rasterImage.Pixels[10] should be 0xFF01FD00"); | |
AssertIsTrue((uint)rasterImage.Pixels[0] == 0xFF0000FF, "rasterImage.Pixels[0] should be 0xFF0000FF"); | |
AssertIsTrue(Math.Abs(0.999875 - rasterImage.Width) < DefaultTolerance, "rasterImage.Width should be 0.99987"); | |
AssertIsTrue(Math.Abs(0.999875 - rasterImage.Height) < DefaultTolerance, "rasterImage.Height should be 0.99987"); | |
AssertIsTrue(Math.Abs(387 - rasterImage.OffsetX) < DefaultTolerance, "rasterImage.OffsetX should be 387"); | |
AssertIsTrue(Math.Abs(379 - rasterImage.OffsetY) < DefaultTolerance, "rasterImage.OffsetY should be 379"); | |
AssertIsTrue(Math.Abs(0 - rasterImage.Angle) < DefaultTolerance, "rasterImage.Angle should be 0"); | |
AssertIsTrue(Math.Abs(0 - rasterImage.LeftBottomShift) < DefaultTolerance, "rasterImage.LeftBottomShift should be 0"); | |
AssertIsTrue(Math.Abs(0 - rasterImage.ImageRectangle.X) < DefaultTolerance, "rasterImage.ImageRectangle.X should be 0"); | |
AssertIsTrue(Math.Abs(0 - rasterImage.ImageRectangle.Y) < DefaultTolerance, "rasterImage.ImageRectangle.Y should be 0"); | |
AssertIsTrue(Math.Abs(10 - rasterImage.ImageRectangle.Width) < DefaultTolerance, "rasterImage.ImageRectangle.Width should be 10"); | |
AssertIsTrue(Math.Abs(10 - rasterImage.ImageRectangle.Height) < DefaultTolerance, "rasterImage.ImageRectangle.Height should be 10"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Load PSD image. | |
using (PsdImage image = (PsdImage)Image.Load(dataDir + "aspose_out.psd")) | |
{ | |
// Iterate over resources. | |
foreach (var resource in image.ImageResources) | |
{ | |
// Find thumbnail resource. Typically they are in the Jpeg file format. | |
if (resource is ThumbnailResource || resource is Thumbnail4Resource) | |
{ | |
// Adjust thumbnail data. | |
var thumbnail = (ThumbnailResource)resource; | |
var exifData = new JpegExifData(); | |
var thumbnailImage = new PsdImage(100, 100); | |
try | |
{ | |
// Fill thumbnail data. | |
int[] pixels = new int[thumbnailImage.Width * thumbnailImage.Height]; | |
for (int i = 0; i < pixels.Length; i++) | |
{ | |
pixels[i] = i; | |
} | |
// Assign thumbnail data. | |
thumbnailImage.SaveArgb32Pixels(thumbnailImage.Bounds, pixels); | |
exifData.Thumbnail = thumbnailImage; | |
thumbnail.JpegOptions.ExifData = exifData; | |
} | |
catch | |
{ | |
thumbnailImage.Dispose(); | |
throw; | |
} | |
} | |
} | |
image.Save(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Load PSD image. | |
using (PsdImage image = (PsdImage)Image.Load(dataDir + "aspose_out.psd")) | |
{ | |
// Iterate over resources. | |
foreach (var resource in image.ImageResources) | |
{ | |
// Find thumbnail resource. Typically they are in the Jpeg file format. | |
if (resource is ThumbnailResource || resource is Thumbnail4Resource) | |
{ | |
// Adjust thumbnail data. | |
var thumbnail = (ThumbnailResource)resource; | |
var jfifData = new FileFormats.Jpeg.JFIFData(); | |
var thumbnailImage = new PsdImage(100, 100); | |
try | |
{ | |
// Fill thumbnail data. | |
int[] pixels = new int[thumbnailImage.Width * thumbnailImage.Height]; | |
for (int i = 0; i < pixels.Length; i++) | |
{ | |
pixels[i] = i; | |
} | |
// Assign thumbnail data. | |
thumbnailImage.SaveArgb32Pixels(thumbnailImage.Bounds, pixels); | |
jfifData.Thumbnail = thumbnailImage; | |
jfifData.XDensity = 1; | |
jfifData.YDensity = 1; | |
thumbnail.JpegOptions.Jfif = jfifData; | |
} | |
catch | |
{ | |
thumbnailImage.Dispose(); | |
throw; | |
} | |
} | |
} | |
image.Save(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Load PSD image. | |
using (PsdImage image = (PsdImage)Image.Load(dataDir + "PsdImage.psd")) | |
{ | |
JpegOptions options = new JpegOptions(); | |
options.ColorType = JpegCompressionColorMode.Grayscale; | |
options.CompressionType = JpegCompressionMode.Progressive; | |
image.Save(dataDir + "ColorTypeAndCompressionType_output.jpg", options); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Load PSD image. | |
using (PsdImage image = (PsdImage)Image.Load(dataDir + "1280px-Zebras_Serengeti.psd")) | |
{ | |
// Iterate over resources. | |
foreach (var resource in image.ImageResources) | |
{ | |
// Find thumbnail resource. Typically they are in the Jpeg file format. | |
if (resource is ThumbnailResource || resource is Thumbnail4Resource) | |
{ | |
// Extract thumbnail data and store it as a separate image file. | |
var thumbnail = (ThumbnailResource)resource; | |
var jfif = thumbnail.JpegOptions.Jfif; | |
if (jfif != null) | |
{ | |
// extract JFIF data and process. | |
} | |
var exif = thumbnail.JpegOptions.ExifData; | |
if (exif != null) | |
{ | |
// extract Exif data and process. | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Load PSD image. | |
using (PsdImage image = (PsdImage)Image.Load(dataDir + "1280px-Zebras_Serengeti.psd")) | |
{ | |
// Iterate over resources. | |
foreach (var resource in image.ImageResources) | |
{ | |
// Find thumbnail resource. Typically they are in the Jpeg file format. | |
if (resource is ThumbnailResource || resource is Thumbnail4Resource) | |
{ | |
// Extract thumbnail data and store it as a separate image file. | |
var thumbnail = (ThumbnailResource)resource; | |
var data = ((ThumbnailResource)resource).ThumbnailArgb32Data; | |
using (PsdImage extractedThumnailImage = new PsdImage(thumbnail.Width, thumbnail.Height)) | |
{ | |
extractedThumnailImage.SaveArgb32Pixels(extractedThumnailImage.Bounds, data); | |
extractedThumnailImage.Save(dataDir + "extracted_thumbnail.jpg", new JpegOptions()); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
using (PsdImage image = (PsdImage)Image.Load(dataDir + "1280px-Zebras_Serengeti.psd")) | |
{ | |
// Iterate over resources. | |
foreach (var resource in image.ImageResources) | |
{ | |
// Find thumbnail resource. Typically they are in the Jpeg file format. | |
if (resource is ThumbnailResource || resource is Thumbnail4Resource) | |
{ | |
// Extract thumbnail data and store it as a separate image file. | |
var thumbnail = (ThumbnailResource)resource; | |
var exifData = thumbnail.JpegOptions.ExifData; | |
if (exifData != null) | |
{ | |
Type type = exifData.GetType(); | |
PropertyInfo[] properties = type.GetProperties(); | |
foreach (PropertyInfo property in properties) | |
{ | |
Console.WriteLine(property.Name + ":" + property.GetValue(exifData, null)); | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Load PSD image. | |
using (PsdImage image = (PsdImage)Image.Load(dataDir + "PsdImage.psd")) | |
{ | |
JpegOptions options = new JpegOptions(); | |
// Set 2 bits per sample to see the difference in size and quality | |
byte bpp = 2; | |
//Just replace one line given below in examples to use YCCK instead of CMYK | |
//options.ColorType = JpegCompressionColorMode.Cmyk; | |
options.ColorType = JpegCompressionColorMode.Cmyk; | |
options.CompressionType = JpegCompressionMode.JpegLs; | |
options.BitsPerChannel = bpp; | |
// The default profiles will be used. | |
options.RgbColorProfile = null; | |
options.CmykColorProfile = null; | |
image.Save(dataDir + "2_7BitsJPEG_output.jpg", options); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Load PSD image. | |
using (PsdImage image = (PsdImage)Image.Load(dataDir + "PsdImage.psd")) | |
{ | |
JpegOptions options = new JpegOptions(); | |
//Just replace one line given below in examples to use YCCK instead of CMYK | |
//options.ColorType = JpegCompressionColorMode.Cmyk; | |
options.ColorType = JpegCompressionColorMode.Cmyk; | |
options.CompressionType = JpegCompressionMode.JpegLs; | |
// The default profiles will be used. | |
options.RgbColorProfile = null; | |
options.CmykColorProfile = null; | |
image.Save(dataDir + "output.jpg", options); | |
} | |
// Load PSD image. | |
using (PsdImage image = (PsdImage)Image.Load(dataDir + "PsdImage.psd")) | |
{ | |
JpegOptions options = new JpegOptions(); | |
//Just replace one line given below in examples to use YCCK instead of CMYK | |
//options.ColorType = JpegCompressionColorMode.Cmyk; | |
options.ColorType = JpegCompressionColorMode.Cmyk; | |
options.CompressionType = JpegCompressionMode.Lossless; | |
// The default profiles will be used. | |
options.RgbColorProfile = null; | |
options.CmykColorProfile = null; | |
image.Save(dataDir + "output2.jpg", options); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Load PSD image. | |
using (PsdImage image = (PsdImage)Image.Load(dataDir + "sample.psd")) | |
{ | |
// Iterate over resources. | |
foreach (var resource in image.ImageResources) | |
{ | |
// Find thumbnail resource. Typically they are in the Jpeg file format. | |
if (resource is ThumbnailResource || resource is Thumbnail4Resource) | |
{ | |
// Extract exif data and print to the console. | |
var exif = ((ThumbnailResource)resource).JpegOptions.ExifData; | |
if (exif != null) | |
{ | |
// Set LensMake, WhiteBalance, Flash information Save the image | |
exif.LensMake = "Sony"; | |
exif.WhiteBalance = ExifWhiteBalance.Auto; | |
exif.Flash = ExifFlash.Fired; | |
} | |
} | |
} | |
image.Save(dataDir + "aspose_out.psd"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Load a PSD file as an image and cast it into PsdImage | |
using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "sample.psd")) | |
{ | |
// Create an instance of PngOptions, Set the PNG filter method and Save changes to the disc | |
PngOptions options = new PngOptions(); | |
options.FilterType = PngFilterType.Paeth; | |
psdImage.Save(dataDir + "ApplyFilterMethod_out.png", options); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Load a PSD file as an image and cast it into PsdImage | |
using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "sample.psd")) | |
{ | |
int[] pixels = psdImage.LoadArgb32Pixels(psdImage.Bounds); | |
// Iterate through the pixel array and Check the pixel information | |
//that if it is a transparent color pixel and Change the pixel color to white | |
int transparent = psdImage.TransparentColor.ToArgb(); | |
int replacementColor = Color.Yellow.ToArgb(); | |
for (int i = 0; i < pixels.Length; i++) | |
{ | |
if (pixels[i] == transparent) | |
{ | |
pixels[i] = replacementColor; | |
} | |
} | |
// Replace the pixel array into the image. | |
psdImage.SaveArgb32Pixels(psdImage.Bounds, pixels); | |
psdImage.Save(dataDir + "ChangeBackground_out.png", new PngOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Load a PSD file as an image and cast it into PsdImage | |
using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "sample.psd")) | |
{ | |
// Loop over possible CompressionLevel range | |
for (int i = 0; i <= 9; i++) | |
{ | |
// Create an instance of PngOptions for each resultant PNG, Set CompressionLevel and Save result on disk | |
PngOptions options = new PngOptions(); | |
options.CompressionLevel = i; | |
psdImage.Save(dataDir + i + "_out.png", options); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Load a PSD file as an image and cast it into PsdImage | |
using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "sample.psd")) | |
{ | |
// Create an instance of PngOptions, Set the horizontal & vertical resolutions and Save the result on disc | |
PngOptions options = new PngOptions(); | |
options.ResolutionSettings = new ResolutionSetting(72, 96); | |
psdImage.Save(dataDir + "SettingResolution_output.png", options); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Load a PSD file as an image and cast it into PsdImage | |
using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "sample.psd")) | |
{ | |
// Create an instance of PngOptions, Set the desired ColorType, BitDepth according to the specified ColorType and save image | |
PngOptions options = new PngOptions(); | |
options.ColorType = PngColorType.Grayscale; | |
options.BitDepth = 1; | |
psdImage.Save(dataDir + "SpecifyBitDepth_out.png", options); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Load a PSD file as an image and cast it into PsdImage | |
using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "sample.psd")) | |
{ | |
// specify the PNG image transparency options and save to file. | |
psdImage.TransparentColor = Color.White; | |
psdImage.HasTransparentColor = true; | |
PngOptions opt = new PngOptions(); | |
psdImage.Save(dataDir + "Specify_Transparency_result.png", new PngOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string[] sourceFileNames = new string[] { | |
//Test files with layers | |
"Little", | |
"Simple", | |
//Test files without layers | |
"psb", | |
"psb3" | |
}; | |
var options = new PsdLoadOptions(); | |
foreach (var fileName in sourceFileNames) | |
{ | |
var sourceFileName = dataDir + fileName + ".psb"; | |
using (PsdImage image = (PsdImage)Image.Load(sourceFileName, options)) | |
{ | |
// All jpeg and psd files must be readable | |
image.Save(dataDir + fileName + "_output.jpg", new JpegOptions() { Quality = 95 }); | |
image.Save(dataDir + fileName + "_output.psb"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFileName = dataDir + "Simple.psb"; | |
using (PsdImage image = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
string outFileName = dataDir + "Simple.pdf"; | |
image.Save(outFileName, new PdfOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFilePathPsb = dataDir + "2layers.psb"; | |
string outputFilePathPsd = dataDir + "ConvertFromPsb.psd"; | |
using (Image img = Image.Load(sourceFilePathPsb)) | |
{ | |
var options = new PsdOptions((PsdImage)img) { PsdVersion = PsdVersion.Psd }; | |
img.Save(outputFilePathPsd, options); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFileName = dataDir + "Stripes.psd"; | |
string outputFileName = dataDir + "OutputStripes.psd"; | |
using (PsdImage image = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
BlackWhiteAdjustmentLayer newLayer = image.AddBlackWhiteAdjustmentLayer(); | |
newLayer.Name = "BlackWhiteAdjustmentLayer"; | |
newLayer.Reds = 22; | |
newLayer.Yellows = 92; | |
newLayer.Greens = 70; | |
newLayer.Cyans = 79; | |
newLayer.Blues = 7; | |
newLayer.Magentas = 28; | |
image.Save(outputFileName, new PsdOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFileName = dataDir + "ChannelMixerAdjustmentLayerRgb.psd"; | |
string psdPathAfterChange = dataDir + "ChannelMixerAdjustmentLayerRgbChanged.psd"; | |
using (var im = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
foreach (var layer in im.Layers) | |
{ | |
if (layer is RgbChannelMixerLayer) | |
{ | |
var rgbLayer = (RgbChannelMixerLayer)layer; | |
rgbLayer.RedChannel.Blue = 100; | |
rgbLayer.BlueChannel.Green = -100; | |
rgbLayer.GreenChannel.Constant = 50; | |
} | |
} | |
im.Save(psdPathAfterChange); | |
} | |
// Cmyk Channel Mixer | |
sourceFileName = dataDir + "ChannelMixerAdjustmentLayerCmyk.psd"; | |
psdPathAfterChange = dataDir + "ChannelMixerAdjustmentLayerCmykChanged.psd"; | |
using (var im = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
foreach (var layer in im.Layers) | |
{ | |
if (layer is CmykChannelMixerLayer) | |
{ | |
var cmykLayer = (CmykChannelMixerLayer)layer; | |
cmykLayer.CyanChannel.Black = 20; | |
cmykLayer.MagentaChannel.Yellow = 50; | |
cmykLayer.YellowChannel.Cyan = -25; | |
cmykLayer.BlackChannel.Yellow = 25; | |
} | |
} | |
im.Save(psdPathAfterChange); | |
} | |
// Adding the new layer(Cmyk for this example) | |
sourceFileName = dataDir + "CmykWithAlpha.psd"; | |
psdPathAfterChange = dataDir + "ChannelMixerAdjustmentLayerCmykChanged.psd"; | |
using (var im = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
var newlayer = im.AddChannelMixerAdjustmentLayer(); | |
newlayer.GetChannelByIndex(2).Constant = 50; | |
newlayer.GetChannelByIndex(0).Constant = 50; | |
im.Save(psdPathAfterChange); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Curves layer editing | |
string sourceFileName = dataDir + "CurvesAdjustmentLayer"; | |
string psdPathAfterChange = dataDir + "CurvesAdjustmentLayerChanged"; | |
for (int j = 1; j < 2; j++) | |
{ | |
using (var im = (PsdImage)Image.Load(sourceFileName + j.ToString() + ".psd")) | |
{ | |
foreach (var layer in im.Layers) | |
{ | |
if (layer is CurvesLayer) | |
{ | |
var curvesLayer = (CurvesLayer)layer; | |
if (curvesLayer.IsDiscreteManagerUsed) | |
{ | |
var manager = (CurvesDiscreteManager)curvesLayer.GetCurvesManager(); | |
for (int i = 10; i < 50; i++) | |
{ | |
manager.SetValueInPosition(0, (byte)i, (byte)(15 + (i * 2))); | |
} | |
} | |
else | |
{ | |
var manager = (CurvesContinuousManager)curvesLayer.GetCurvesManager(); | |
manager.AddCurvePoint(0, 50, 100); | |
manager.AddCurvePoint(0, 150, 130); | |
} | |
} | |
} | |
// Save PSD | |
im.Save(psdPathAfterChange + j.ToString() + ".psd"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Load a PSD file as an image and cast it into PsdImage | |
using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "layers.psd")) | |
{ | |
// Create graphics object to perform draw operations. | |
Graphics graphics = new Graphics(psdImage); | |
// Create font to draw watermark with. | |
Font font = new Font("Arial", 20.0f); | |
// Create a solid brush with color alpha set near to 0 to use watermarking effect. | |
using (SolidBrush brush = new SolidBrush(Color.FromArgb(50, 128, 128, 128))) | |
{ | |
// specify transform matrix to rotate watermark. | |
graphics.Transform = new Matrix(); | |
graphics.Transform.RotateAt(45, new PointF(psdImage.Width / 2, psdImage.Height / 2)); | |
// Specify string alignment to put watermark at the image center. | |
StringFormat sf = new StringFormat(); | |
sf.Alignment = StringAlignment.Center; | |
// Draw watermark using font, partly-transparent brush at the image center. | |
graphics.DrawString("Some watermark text", font, brush, new RectangleF(0, psdImage.Height / 2, psdImage.Width, psdImage.Height / 2), sf); | |
} | |
// Export the image into PNG file format. | |
psdImage.Save(dataDir + "AddDiagnolWatermark_output.png", new PngOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Hue/Saturation layer editing | |
string sourceFileName = dataDir + "HueSaturationAdjustmentLayer.psd"; | |
string psdPathAfterChange = dataDir + "HueSaturationAdjustmentLayerChanged.psd"; | |
using (var im = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
foreach (var layer in im.Layers) | |
{ | |
if (layer is HueSaturationLayer) | |
{ | |
var hueLayer = (HueSaturationLayer)layer; | |
hueLayer.Hue = -25; | |
hueLayer.Saturation = -12; | |
hueLayer.Lightness = 67; | |
var colorRange = hueLayer.GetRange(2); | |
colorRange.Hue = -40; | |
colorRange.Saturation = 50; | |
colorRange.Lightness = -20; | |
colorRange.MostLeftBorder = 300; | |
} | |
} | |
im.Save(psdPathAfterChange); | |
} | |
// Hue/Saturation layer adding | |
sourceFileName = dataDir + "PhotoExample.psd"; | |
psdPathAfterChange = dataDir + "PhotoExampleAddedHueSaturation.psd"; | |
using (PsdImage im = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
//this.SaveForVisualTest(im, this.OutputPath, prefix + file, "before"); | |
var hueLayer = im.AddHueSaturationAdjustmentLayer(); | |
hueLayer.Hue = -25; | |
hueLayer.Saturation = -12; | |
hueLayer.Lightness = 67; | |
var colorRange = hueLayer.GetRange(2); | |
colorRange.Hue = -160; | |
colorRange.Saturation = 100; | |
colorRange.Lightness = 20; | |
colorRange.MostLeftBorder = 300; | |
im.Save(psdPathAfterChange); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFileName = dataDir + "FillOpacitySample.psd"; | |
string exportPath = dataDir + "FillOpacitySampleChanged.psd"; | |
using (var im = (PsdImage)(Image.Load(sourceFileName))) | |
{ | |
var layer = im.Layers[2]; | |
var resources = layer.Resources; | |
foreach (var resource in resources) | |
{ | |
if (resource is FileFormats.Psd.Layers.LayerResources.IopaResource) | |
{ | |
var iopaResource = (IopaResource)resource; | |
iopaResource.FillOpacity = 200; | |
} | |
} | |
im.Save(exportPath); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFileName = dataDir + "LevelsAdjustmentLayer.psd"; | |
string psdPathAfterChange = dataDir + "LevelsAdjustmentLayerChanged.psd"; | |
using (var im = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
foreach (var layer in im.Layers) | |
{ | |
if (layer is LevelsLayer) | |
{ | |
var levelsLayer = (LevelsLayer)layer; | |
var channel = levelsLayer.GetChannel(0); | |
channel.InputMidtoneLevel = 2.0f; | |
channel.InputShadowLevel = 10; | |
channel.InputHighlightLevel = 230; | |
channel.OutputShadowLevel = 20; | |
channel.OutputHighlightLevel = 200; | |
} | |
} | |
// Save PSD | |
im.Save(psdPathAfterChange); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string outFileName = dataDir + "OneLayerWithAddedText.psd"; | |
using (PsdImage image = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
image.AddTextLayer("Some text", new Rectangle(50, 50, 100, 100)); | |
PsdOptions options = new PsdOptions(image); | |
image.Save(outFileName, options); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFileName = dataDir + "OneLayer.psd"; | |
string psdPath = dataDir + "ImageWithTextLayer.psd"; | |
using (var img = Image.Load(sourceFileName)) | |
{ | |
PsdImage im = (PsdImage)img; | |
var rect = new Rectangle( | |
(int)(im.Width * 0.25), | |
(int)(im.Height * 0.25), | |
(int)(im.Width * 0.5), | |
(int)(im.Height * 0.5)); | |
var layer = im.AddTextLayer("Added text", rect); | |
im.Save(psdPath); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Load a PSD file as an image and cast it into PsdImage | |
using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "layers.psd")) | |
{ | |
// Create graphics object to perform draw operations. | |
Graphics graphics = new Graphics(psdImage); | |
// Create font to draw watermark with. | |
Font font = new Font("Arial", 20.0f); | |
// Create a solid brush with color alpha set near to 0 to use watermarking effect. | |
using (SolidBrush brush = new SolidBrush(Color.FromArgb(50, 128, 128, 128))) | |
{ | |
// Specify string alignment to put watermark at the image center. | |
StringFormat sf = new StringFormat(); | |
sf.Alignment = StringAlignment.Center; | |
sf.LineAlignment = StringAlignment.Center; | |
// Draw watermark using font, partly-transparent brush and rotation matrix at the image center. | |
graphics.DrawString("Some watermark text", font, brush, new RectangleF(0, 0, psdImage.Width, psdImage.Height), sf); | |
} | |
// Export the image into PNG file format. | |
psdImage.Save(dataDir + "AddWatermark_output.png", new PngOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFileName = dataDir + "ColorFillLayer.psd"; | |
string exportPath = dataDir + "ColorFillLayer_output.psd"; | |
var im = (PsdImage)Image.Load(sourceFileName); | |
using (im) | |
{ | |
foreach (var layer in im.Layers) | |
{ | |
if (layer is FillLayer) | |
{ | |
var fillLayer = (FillLayer)layer; | |
if (fillLayer.FillSettings.FillType != FillType.Color) | |
{ | |
throw new Exception("Wrong Fill Layer"); | |
} | |
var settings = (IColorFillSettings)fillLayer.FillSettings; | |
settings.Color = Color.Red; | |
fillLayer.Update(); | |
im.Save(exportPath); | |
break; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Load a PSD file as an image and caste it into PsdImage | |
using (PsdImage image = (PsdImage)Image.Load(dataDir + "sample.psd")) | |
{ | |
foreach (var layer in image.Layers) | |
{ | |
if (layer.Name == "Rectangle 1") | |
{ | |
layer.HasBackgroundColor = true; | |
layer.BackgroundColor = Color.Orange; | |
} | |
} | |
image.Save(dataDir + "asposeImage02.psd"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// By default the cache folder is set to the local temp directory. You can specify a different cache folder from the default this way: | |
Cache.CacheFolder = dataDir; | |
// Set cache on disk. | |
Cache.CacheType = CacheType.CacheOnDiskOnly; | |
// The default cache max value is 0, which means that there is no upper limit | |
Cache.MaxDiskSpaceForCache = 1073741824; // 1 gigabyte | |
Cache.MaxMemoryForCache = 1073741824; // 1 gigabyte | |
// We do not recommend that you change the following property because it may greatly affect performance | |
Cache.ExactReallocateOnly = false; | |
// At any time you can check how many bytes are currently allocated for the cache in memory or on disk By examining the following properties | |
long l1 = Cache.AllocatedDiskBytesCount; | |
long l2 = Cache.AllocatedMemoryBytesCount; | |
PsdOptions options = new PsdOptions(); | |
//GifOptions options = new GifOptions(); | |
options.Palette = new ColorPalette(new[] { Color.Red, Color.Blue, Color.Black, Color.White }); | |
options.Source = new StreamSource(new MemoryStream(), true); | |
using (RasterImage image = (RasterImage)Image.Create(options, 100, 100)) | |
{ | |
Color[] pixels = new Color[10000]; | |
for (int i = 0; i < pixels.Length; i++) | |
{ | |
pixels[i] = Color.White; | |
} | |
image.SavePixels(image.Bounds, pixels); | |
// After executing the code above 40000 bytes are allocated to disk. | |
long diskBytes = Cache.AllocatedDiskBytesCount; | |
long memoryBytes = Cache.AllocatedMemoryBytesCount; | |
} | |
// The allocation properties may be used to check whether all Aspose.Imaging objects were properly disposed. If you've forgotten to call dispose on an object the cache values will not be 0. | |
l1 = Cache.AllocatedDiskBytesCount; | |
l2 = Cache.AllocatedMemoryBytesCount; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string inputFile = dataDir + "PsdConvertToExample.psd"; | |
using (var psdImage = (PsdImage)Image.Load(inputFile)) | |
{ | |
psdImage.Save(dataDir + "PsdConvertedToJpg.jpg", new JpegOptions() {Quality = 80, JpegLsAllowedLossyError = 10 }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string inputFile = dataDir + "PsdConvertToPdfExample.psd"; | |
using (var psdImage = (PsdImage)Image.Load(inputFile, new PsdLoadOptions())) | |
{ | |
psdImage.Save(dataDir + "PsdConvertedToPdf.pdf", | |
new PdfOptions() { | |
PdfDocumentInfo = new PdfDocumentInfo() | |
{ | |
Author = "Aspose.PSD", | |
Keywords = "Convert,Psd,Pdf,Online,HowTo", | |
Subject = "PSD Conversion to PDF", | |
Title = "Pdf From Psd", | |
}, | |
ResolutionSettings = new ResolutionSetting(5, 6) | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string inputFile = dataDir + "PsdConvertToPngExample.psd"; | |
using (var psdImage = (PsdImage)Image.Load(inputFile, new PsdLoadOptions() { ReadOnlyMode = true })) | |
{ | |
psdImage.Save(dataDir + "PsdConvertedToPng.png", | |
new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha, Progressive = true, CompressionLevel = 9 }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Create an instance of PsdOptions and set it's properties | |
var createOptions = new PsdOptions(); | |
createOptions.Source = new FileCreateSource(dataDir + "Newsample_out.psd", false); | |
createOptions.ColorMode = ColorModes.Indexed; | |
createOptions.Version = 5; | |
// Create a new color palette having RGB colors, Set Palette property & compression method | |
Color[] palette = { Color.Red, Color.Green, Color.Blue, Color.Yellow }; | |
createOptions.Palette = new PsdColorPalette(palette); | |
createOptions.CompressionMethod = CompressionMethod.RLE; | |
// Create a new PSD with PsdOptions created previously | |
using (var psd = Image.Create(createOptions, 500, 500)) | |
{ | |
// Draw some graphics over the newly created PSD | |
var graphics = new Graphics(psd); | |
graphics.Clear(Color.White); | |
graphics.DrawEllipse(new Pen(Color.Red, 6), new Rectangle(0, 0, 400, 400)); | |
psd.Save(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string inputFile = dataDir + "ButtonTemp.psd"; | |
var createOptions = new PsdOptions(); | |
createOptions.Source = new FileCreateSource(inputFile, false); | |
createOptions.Palette = new PsdColorPalette(new Color[] { Color.Green }); | |
using (var psdImage = (PsdImage)Image.Create(createOptions, 500, 500)) | |
{ | |
LayerGroup group1 = psdImage.AddLayerGroup("Group 1", 0, true); | |
Layer layer1 = new Layer(psdImage); | |
layer1.Name = "Layer 1"; | |
group1.AddLayer(layer1); | |
LayerGroup group2 = group1.AddLayerGroup("Group 2", 1); | |
Layer layer2 = new Layer(psdImage); | |
layer2.Name = "Layer 2"; | |
group2.AddLayer(layer2); | |
Layer layer3 = new Layer(psdImage); | |
layer3.Name = "Layer 3"; | |
group2.AddLayer(layer3); | |
Layer layer4 = new Layer(psdImage); | |
layer4.Name = "Layer 4"; | |
group1.AddLayer(layer4); | |
psdImage.Save(dataDir + "LayerGroups_out.psd"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Load a PSD file as an image and caste it into PsdImage | |
using (PsdImage image = (PsdImage)Image.Load(dataDir + "sample.psd")) | |
{ | |
int index = 0; | |
// Iterate over the PSD resources | |
foreach (var resource in image.ImageResources) | |
{ | |
index++; | |
// Check if the resource is of thumbnail type | |
if (resource is ThumbnailResource) | |
{ | |
// Retrieve the ThumbnailResource and Check the format of the ThumbnailResource | |
var thumbnail = (ThumbnailResource)resource; | |
if (thumbnail.Format == ThumbnailFormat.KJpegRgb) | |
{ | |
// Create a new image by specifying the width and height, Store the pixels of thumbnail on to the newly created image and save image | |
PsdImage thumnailImage = new PsdImage(thumbnail.Width, thumbnail.Height); | |
thumnailImage.SavePixels(thumnailImage.Bounds, thumbnail.ThumbnailData); | |
thumnailImage.Save(dataDir + "CreateThumbnailsFromPSDFiles_out_" + index.ToString() + ".bmp", new BmpOptions()); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Load a PSD file as an image and cast it into PsdImage | |
using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "layers.psd")) | |
{ | |
// Do processing, Get the true value if PSD is flatten and false in case the PSD is not flatten. | |
Console.WriteLine(psdImage.IsFlatten); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Create a new image from scratch. | |
using (PsdImage image = new PsdImage(300, 300)) | |
{ | |
// Fill image data. | |
Graphics graphics = new Graphics(image); | |
graphics.Clear(Color.White); | |
var pen = new Pen(Color.Brown); | |
graphics.DrawRectangle(pen, image.Bounds); | |
// Create an instance of PsdOptions, Set it's various properties Save image to disk in PSD format | |
PsdOptions psdOptions = new PsdOptions(); | |
psdOptions.ColorMode = ColorModes.Rgb; | |
psdOptions.CompressionMethod = CompressionMethod.Raw; | |
psdOptions.Version = 4; | |
image.Save(dataDir + "ExportImageToPSD_output.psd", psdOptions); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Load a PSD file as an image and caste it into PsdImage | |
using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "sample.psd")) | |
{ | |
// Create an instance of PngOptions class | |
var pngOptions = new PngOptions(); | |
pngOptions.ColorType = PngColorType.TruecolorWithAlpha; | |
// Loop through the list of layers | |
for (int i = 0; i < psdImage.Layers.Length; i++) | |
{ | |
// Convert and save the layer to PNG file format. | |
psdImage.Layers[i].Save(string.Format("layer_out{0}.png", i + 1), pngOptions); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// make changes in layer names and save it | |
using (var image = (PsdImage)Image.Load(dataDir + "Korean_layers.psd")) | |
{ | |
for (int i = 0; i < image.Layers.Length; i++) | |
{ | |
var layer = image.Layers[i]; | |
// set new value into DisplayName property | |
layer.DisplayName += "_changed"; | |
} | |
image.Save(dataDir + "Korean_layers_output.psd"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Change the Fill Opacity property | |
string sourceFileName = dataDir + "FillOpacitySample.psd"; | |
string exportPath = dataDir + "FillOpacitySampleChanged.psd"; | |
using (var im = (PsdImage)(Image.Load(sourceFileName))) | |
{ | |
var layer = im.Layers[2]; | |
layer.FillOpacity = 5; | |
im.Save(exportPath); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
{ | |
List<ITextPortion> regularText = new List<ITextPortion>(); | |
List<ITextPortion> boldText = new List<ITextPortion>(); | |
List<ITextPortion> italicText = new List<ITextPortion>(); | |
var layers = psdImage.Layers; | |
for (int index = 0; index < layers.Length; index++) | |
{ | |
var layer = layers[index]; | |
if (!(layer is TextLayer)) | |
{ | |
continue; | |
} | |
var textLayer = (TextLayer)layer; | |
// gets fonts that contains in text layer | |
var fonts = textLayer.GetFonts(); | |
var textPortions = textLayer.TextData.Items; | |
foreach (var textPortion in textPortions) | |
{ | |
TextFontInfo font = fonts[textPortion.Style.FontIndex]; | |
if (font != null) | |
{ | |
switch (font.Style) | |
{ | |
case FontStyle.Regular: | |
regularText.Add(textPortion); | |
break; | |
case FontStyle.Bold: | |
boldText.Add(textPortion); | |
break; | |
case FontStyle.Italic: | |
italicText.Add(textPortion); | |
break; | |
default: | |
throw new ArgumentOutOfRangeException(); | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
const double Tolerance = 0.0001; | |
var filePath = dataDir + "ThreeColorsParagraphs.psd"; | |
var outputPath = dataDir + "ThreeColorsParagraph_out.psd"; | |
using (var im = (PsdImage)Image.Load(filePath)) | |
{ | |
for (int i = 0; i < im.Layers.Length; i++) | |
{ | |
var layer = im.Layers[i] as TextLayer; | |
if (layer != null) | |
{ | |
var portions = layer.TextData.Items; | |
if (portions.Length != 4) | |
{ | |
throw new Exception(); | |
} | |
// Checking text of every portion | |
if (portions[0].Text != "Old " || | |
portions[1].Text != "color" || | |
portions[2].Text != " text\r" || | |
portions[3].Text != "Second paragraph\r") | |
{ | |
throw new Exception(); | |
} | |
// Checking paragraphs data | |
// Paragraphs have different justification | |
if ( | |
portions[0].Paragraph.Justification != 0 || | |
portions[1].Paragraph.Justification != 0 || | |
portions[2].Paragraph.Justification != 0 || | |
portions[3].Paragraph.Justification != 2) | |
{ | |
throw new Exception(); | |
} | |
// All other properties of first and second paragraph are equal | |
for (int j = 0; j < portions.Length; j++) | |
{ | |
var paragraph = portions[j].Paragraph; | |
if (Math.Abs(paragraph.AutoLeading - 1.2) > Tolerance || | |
paragraph.AutoHyphenate != false || | |
paragraph.Burasagari != false || | |
paragraph.ConsecutiveHyphens != 8 || | |
Math.Abs(paragraph.StartIndent) > Tolerance || | |
Math.Abs(paragraph.EndIndent) > Tolerance || | |
paragraph.EveryLineComposer != false || | |
Math.Abs(paragraph.FirstLineIndent) > Tolerance || | |
paragraph.GlyphSpacing.Length != 3 || | |
Math.Abs(paragraph.GlyphSpacing[0] - 1) > Tolerance || | |
Math.Abs(paragraph.GlyphSpacing[1] - 1) > Tolerance || | |
Math.Abs(paragraph.GlyphSpacing[2] - 1) > Tolerance || | |
paragraph.Hanging != false || | |
paragraph.HyphenatedWordSize != 6 || | |
paragraph.KinsokuOrder != 0 || | |
paragraph.LetterSpacing.Length != 3 || | |
Math.Abs(paragraph.LetterSpacing[0]) > Tolerance || | |
Math.Abs(paragraph.LetterSpacing[1]) > Tolerance || | |
Math.Abs(paragraph.LetterSpacing[2]) > Tolerance || | |
paragraph.LeadingType != LeadingMode.Auto || | |
paragraph.PreHyphen != 2 || | |
paragraph.PostHyphen != 2 || | |
Math.Abs(paragraph.SpaceBefore) > Tolerance || | |
Math.Abs(paragraph.SpaceAfter) > Tolerance || | |
paragraph.WordSpacing.Length != 3 || | |
Math.Abs(paragraph.WordSpacing[0] - 0.8) > Tolerance || | |
Math.Abs(paragraph.WordSpacing[1] - 1.0) > Tolerance || | |
Math.Abs(paragraph.WordSpacing[2] - 1.33) > Tolerance || | |
Math.Abs(paragraph.Zone - 36.0) > Tolerance) | |
{ | |
throw new Exception(); | |
} | |
} | |
// Checking style data | |
// Styles have different colors and font size | |
if (Math.Abs(portions[0].Style.FontSize - 12) > Tolerance || | |
Math.Abs(portions[1].Style.FontSize - 12) > Tolerance || | |
Math.Abs(portions[2].Style.FontSize - 12) > Tolerance || | |
Math.Abs(portions[3].Style.FontSize - 10) > Tolerance) | |
{ | |
throw new Exception(); | |
} | |
if (portions[0].Style.FillColor != Color.FromArgb(255, 145, 0, 0) || | |
portions[1].Style.FillColor != Color.FromArgb(255, 201, 128, 2) || | |
portions[2].Style.FillColor != Color.FromArgb(255, 18, 143, 4) || | |
portions[3].Style.FillColor != Color.FromArgb(255, 145, 42, 100)) | |
{ | |
throw new Exception(); | |
} | |
for (int j = 0; j < portions.Length; j++) | |
{ | |
var style = portions[j].Style; | |
if (style.AutoLeading != false || | |
style.HindiNumbers != false || | |
style.Kerning != 0 || | |
style.Leading != 0 || | |
style.StrokeColor != Color.FromArgb(255, 175, 90, 163) || | |
style.Tracking != 50) | |
{ | |
throw new Exception(); | |
} | |
} | |
// Example of text editing | |
portions[0].Text = "Hello "; | |
portions[1].Text = "World"; | |
// Example of text portions removing | |
layer.TextData.RemovePortion(3); | |
layer.TextData.RemovePortion(2); | |
// Example of adding new text portion | |
var createdPortion = layer.TextData.ProducePortion(); | |
createdPortion.Text = "!!!\r"; | |
layer.TextData.AddPortion(createdPortion); | |
portions = layer.TextData.Items; | |
// Example of paragraph and style editing for portions | |
// Set right justification | |
portions[0].Paragraph.Justification = 1; | |
portions[1].Paragraph.Justification = 1; | |
portions[2].Paragraph.Justification = 1; | |
// Different colors for each style. The will be changed, but rendering is not fully supported | |
portions[0].Style.FillColor = Color.Aquamarine; | |
portions[1].Style.FillColor = Color.Violet; | |
portions[2].Style.FillColor = Color.LightBlue; | |
// Different font. The will be changed, but rendering is not fully supported | |
portions[0].Style.FontSize = 6; | |
portions[1].Style.FontSize = 8; | |
portions[2].Style.FontSize = 10; | |
layer.TextData.UpdateLayerData(); | |
im.Save(outputPath, new PsdOptions(im)); | |
break; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_PSD(); | |
string sourceFileName = dataDir + "ComplexGradientFillLayer.psd"; | |
string outputFile = dataDir + "ComplexGradientFillLayer_output.psd"; | |
var image = (PsdImage)Image.Load(sourceFileName); | |
using (image) | |
{ | |
foreach (var layer in image.Layers) | |
{ | |
if (layer is FillLayer) | |
{ | |
var fillLayer = (FillLayer)layer; | |
if (fillLayer.FillSettings.FillType != FillType.Gradient) | |
{ | |
throw new Exception("Wrong Fill Layer"); | |
} | |
var settings = (IGradientFillSettings)fillLayer.FillSettings; | |
if ( | |
Math.Abs(settings.Angle - 45) > 0.25 || | |
settings.Dither != true || | |
settings.AlignWithLayer != false || | |
settings.Reverse != false || | |
Math.Abs(settings.HorizontalOffset - (-39)) > 0.25 || | |
Math.Abs(settings.VerticalOffset - (-5)) > 0.25 || | |
settings.TransparencyPoints.Length != 3 || | |
settings.ColorPoints.Length != 2 || | |
Math.Abs(100.0 - settings.TransparencyPoints[0].Opacity) > 0.25 || | |
settings.TransparencyPoints[0].Location != 0 || | |
settings.TransparencyPoints[0].MedianPointLocation != 50 || | |
settings.ColorPoints[0].Color != Color.FromArgb(203, 64, 140) || | |
settings.ColorPoints[0].Location != 0 || | |
settings.ColorPoints[0].MedianPointLocation != 50) | |
{ | |
throw new Exception("Gradient Fill was not read correctly"); | |
} | |
settings.Angle = 0.0; | |
settings.Dither = false; | |
settings.AlignWithLayer = true; | |
settings.Reverse = true; | |
settings.HorizontalOffset = 25; | |
settings.VerticalOffset = -15; | |
var colorPoints = new List<IGradientColorPoint>(settings.ColorPoints); | |
var transparencyPoints = new List<IGradientTransparencyPoint>(settings.TransparencyPoints); | |
colorPoints.Add(new GradientColorPoint() | |
{ | |
Color = Color.Violet, | |
Location = 4096, | |
MedianPointLocation = 75 | |
}); | |
colorPoints[1].Location = 3000; | |
transparencyPoints.Add(new GradientTransparencyPoint() | |
{ | |
Opacity = 80.0, | |
Location = 4096, | |
MedianPointLocation = 25 | |
}); | |
transparencyPoints[2].Location = 3000; | |
settings.ColorPoints = colorPoints.ToArray(); | |
settings.TransparencyPoints = transparencyPoints.ToArray(); | |
fillLayer.Update(); | |
image.Save(outputFile, new PsdOptions(image)); | |
break; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string fileName = dataDir + "FillLayerGradient.psd"; | |
GradientType[] gradientTypes = new[] | |
{ | |
GradientType.Linear, GradientType.Radial, GradientType.Angle, GradientType.Reflected, GradientType.Diamond | |
}; | |
using (var image = Image.Load(fileName)) | |
{ | |
PsdImage psdImage = (PsdImage)image; | |
FillLayer fillLayer = (FillLayer)psdImage.Layers[0]; | |
GradientFillSettings fillSettings = (GradientFillSettings)fillLayer.FillSettings; | |
foreach (var gradientType in gradientTypes) | |
{ | |
fillSettings.GradientType = gradientType; | |
fillLayer.Update(); | |
psdImage.Save(fileName + "_" + gradientType.ToString() + ".png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string destName = dataDir + "PatternFillLayer_out.psd"; | |
// Load an existing image into an instance of PsdImage class | |
using (var image = (PsdImage)Image.Load(sourceFile)) | |
{ | |
foreach (var layer in image.Layers) | |
{ | |
if (layer is FillLayer) | |
{ | |
var fillLayer = (FillLayer)layer; | |
var settings = (IPatternFillSettings)fillLayer.FillSettings; | |
settings.HorizontalOffset = -5; | |
settings.VerticalOffset = 12; | |
settings.Scale = 300; | |
settings.Linked = true; | |
settings.PatternData = new int[] | |
{ | |
Color.Black.ToArgb(), Color.Red.ToArgb(), | |
Color.Green.ToArgb(), Color.Blue.ToArgb(), | |
Color.White.ToArgb(), Color.AliceBlue.ToArgb(), | |
Color.Violet.ToArgb(), Color.Chocolate.ToArgb(), | |
Color.IndianRed.ToArgb(), Color.DarkOliveGreen.ToArgb(), | |
Color.CadetBlue.ToArgb(), Color.YellowGreen.ToArgb(), | |
Color.Black.ToArgb(), Color.Azure.ToArgb(), | |
Color.ForestGreen.ToArgb(), Color.Sienna.ToArgb(), | |
}; | |
settings.PatternHeight = 4; | |
settings.PatternWidth = 4; | |
settings.PatternName = "$$$/Presets/Patterns/ColorfulSquare=Colorful Square New\0"; | |
settings.PatternId = Guid.NewGuid().ToString() + "\0"; | |
fillLayer.Update(); | |
break; | |
} | |
} | |
image.Save(destName, new PsdOptions(image)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Load a PSD file as an image and caste it into PsdImage | |
using (PsdImage image = (PsdImage)Image.Load(dataDir + "sample.psd")) | |
{ | |
//Extract a layer from PSDImage | |
Layer layer = image.Layers[1]; | |
// Create an image that is needed to be imported into the PSD file. | |
using (PsdImage drawImage = new PsdImage(200, 200)) | |
{ | |
// Fill image surface as needed. | |
Graphics g = new Graphics(drawImage); | |
g.Clear(Color.Yellow); | |
// Call DrawImage method of the Layer class and pass the image instance. | |
layer.DrawImage(new Point(10, 10), drawImage); | |
} | |
// Save the results to output path. | |
image.Save(dataDir + "ImportImageToPSDLayer_out.psd"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
class InterruptMonitorTest | |
{ | |
public static void Run() | |
{ | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_PSB(); | |
InterruptMonitor(dataDir, dataDir); | |
} | |
public static void InterruptMonitor(string dir, string ouputDir) | |
{ | |
ImageOptionsBase saveOptions = new ImageOptions.PngOptions(); | |
Multithreading.InterruptMonitor monitor = new Multithreading.InterruptMonitor(); | |
SaveImageWorker worker = new SaveImageWorker(dir + "big.psb", dir + "big_out.png", saveOptions, monitor); | |
System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(worker.ThreadProc)); | |
try | |
{ | |
thread.Start(); | |
// The timeout should be less than the time required for full image conversion (without interruption). | |
System.Threading.Thread.Sleep(3000); | |
// Interrupt the process | |
monitor.Interrupt(); | |
System.Console.WriteLine("Interrupting the save thread #{0} at {1}", thread.ManagedThreadId, System.DateTime.Now); | |
// Wait for interruption... | |
thread.Join(); | |
} | |
finally | |
{ | |
// If the file to be deleted does not exist, no exception is thrown. | |
System.IO.File.Delete(dir + "big_out.png"); | |
} | |
} | |
} | |
/// <summary> | |
/// Initiates image conversion and waits for its interruption. | |
/// </summary> | |
public class SaveImageWorker | |
{ | |
/// <summary> | |
/// The path to the input image. | |
/// </summary> | |
private readonly string inputPath; | |
/// <summary> | |
/// The path to the output image. | |
/// </summary> | |
private readonly string outputPath; | |
/// <summary> | |
/// The interrupt monitor. | |
/// </summary> | |
private readonly Multithreading.InterruptMonitor monitor; | |
/// <summary> | |
/// The save options. | |
/// </summary> | |
private readonly ImageOptionsBase saveOptions; | |
/// <summary> | |
/// Initializes a new instance of the <see cref="SaveImageWorker" /> class. | |
/// </summary> | |
/// <param name="inputPath">The path to the input image.</param> | |
/// <param name="outputPath">The path to the output image.</param> | |
/// <param name="saveOptions">The save options.</param> | |
/// <param name="monitor">The interrupt monitor.</param> | |
public SaveImageWorker(string inputPath, string outputPath, ImageOptionsBase saveOptions, Multithreading.InterruptMonitor monitor) | |
{ | |
this.inputPath = inputPath; | |
this.outputPath = outputPath; | |
this.saveOptions = saveOptions; | |
this.monitor = monitor; | |
} | |
/// <summary> | |
/// Tries to convert image from one format to another. Handles interruption. | |
/// </summary> | |
public void ThreadProc() | |
{ | |
using (Image image = Image.Load(this.inputPath)) | |
{ | |
Multithreading.InterruptMonitor.ThreadLocalInstance = this.monitor; | |
try | |
{ | |
image.Save(this.outputPath, this.saveOptions); | |
throw new Exception("Expected interruption."); | |
} | |
catch (CoreExceptions.OperationInterruptedException e) | |
{ | |
System.Console.WriteLine("The save thread #{0} finishes at {1}", System.Threading.Thread.CurrentThread.ManagedThreadId, System.DateTime.Now); | |
System.Console.WriteLine(e); | |
} | |
catch (System.Exception e) | |
{ | |
System.Console.WriteLine(e); | |
} | |
finally | |
{ | |
Multithreading.InterruptMonitor.ThreadLocalInstance = null; | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string SourceName = dataDir + "OneLayer.psd"; | |
// Load a PSD file as an image and cast it into PsdImage | |
using (var im = (PsdImage)(Image.Load(SourceName))) | |
{ | |
var layer = im.Layers[0]; | |
var creationDateTime = layer.LayerCreationDateTime; | |
var expectedDateTime = new DateTime(2018, 7, 17, 8, 57, 24, 769); | |
if (expectedDateTime != creationDateTime) | |
{ | |
throw new Exception("Assertion fails"); | |
} | |
var now = DateTime.Now; | |
var createdLayer = im.AddLevelsAdjustmentLayer(); | |
// Check if Creation Date Time Updated on newly created layers | |
if (!(now <= createdLayer.LayerCreationDateTime)) | |
{ | |
throw new Exception("Assertion fails"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFileName = dataDir + "LayerWithText.psd"; | |
string exportPath = dataDir + "LayerEffectsForPSD.png"; | |
using (PsdImage image = (PsdImage)Image.Load(sourceFileName, new ImageLoadOptions.PsdLoadOptions() | |
{ | |
LoadEffectsResource = true, | |
UseDiskForLoadEffectsResource = true | |
})) | |
{ | |
image.Save(exportPath, | |
new ImageOptions.PngOptions() | |
{ | |
ColorType = | |
FileFormats.Png | |
.PngColorType | |
.TruecolorWithAlpha | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string filePath = dataDir + "PsdExample.psd"; | |
string outputFilePath = dataDir + "PsdResult.psd"; | |
using (var image = new PsdImage(200, 200)) | |
{ | |
using (var im = Image.Load(filePath)) | |
{ | |
Layer layer = null; | |
try | |
{ | |
layer = new Layer((RasterImage)im); | |
image.AddLayer(layer); | |
} | |
catch (Exception e) | |
{ | |
if (layer != null) | |
{ | |
layer.Dispose(); | |
} | |
throw; | |
} | |
} | |
image.Save(outputFilePath); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFileName = dataDir + "White 3D Text Effect.psd"; | |
string outFileName = dataDir + "Exported.png"; | |
LoadOptions loadOptions = new PsdLoadOptions() { ReadOnlyMode = true }; | |
ImageOptionsBase saveOptions = new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }; | |
using (PsdImage image = (PsdImage)Image.Load(sourceFileName, loadOptions)) | |
{ | |
image.Save(outFileName, saveOptions); | |
} | |
double memoryUsed = (GC.GetTotalMemory(false) / 1024.0) / 1024.0; | |
// Memory usage must be less then 100 MB for this examples | |
if (memoryUsed > 100) | |
{ | |
throw new Exception("Usage of memory is too big"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Brightness/Contrast layer editing | |
string sourceFileName = dataDir + "BrightnessContrastModern.psd"; | |
string psdPathAfterChange = dataDir + "BrightnessContrastModernChanged.psd"; | |
using (var im = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
foreach (var layer in im.Layers) | |
{ | |
if (layer is BrightnessContrastLayer) | |
{ | |
var brightnessContrastLayer = (BrightnessContrastLayer)layer; | |
brightnessContrastLayer.Brightness = 50; | |
brightnessContrastLayer.Contrast = 50; | |
} | |
} | |
// Save PSD | |
im.Save(psdPathAfterChange); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Rgb Channel Mixer | |
string sourceFileName = dataDir + "ChannelMixerAdjustmentLayerRgb.psd"; | |
string psdPathAfterChange = dataDir + "ChannelMixerAdjustmentLayerRgbChanged.psd"; | |
using (var im = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
foreach (var layer in im.Layers) | |
{ | |
if (layer is RgbChannelMixerLayer) | |
{ | |
var rgbLayer = (RgbChannelMixerLayer)layer; | |
rgbLayer.RedChannel.Blue = 100; | |
rgbLayer.BlueChannel.Green = -100; | |
rgbLayer.GreenChannel.Constant = 50; | |
} | |
} | |
im.Save(psdPathAfterChange); | |
} | |
// Adding the new layer(Cmyk for this example) | |
sourceFileName = dataDir + "CmykWithAlpha.psd"; | |
psdPathAfterChange = dataDir + "ChannelMixerAdjustmentLayerCmykChanged.psd"; | |
using (var im = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
var newlayer = im.AddChannelMixerAdjustmentLayer(); | |
newlayer.GetChannelByIndex(2).Constant = 50; | |
newlayer.GetChannelByIndex(0).Constant = 50; | |
im.Save(psdPathAfterChange); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Exposure layer editing | |
string sourceFileName = dataDir + "ExposureAdjustmentLayer.psd"; | |
string psdPathAfterChange = dataDir + "ExposureAdjustmentLayerChanged.psd"; | |
using (var im = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
foreach (var layer in im.Layers) | |
{ | |
if (layer is ExposureLayer) | |
{ | |
var expLayer = (ExposureLayer)layer; | |
expLayer.Exposure = 2; | |
expLayer.Offset = -0.25f; | |
expLayer.GammaCorrection = 0.5f; | |
} | |
} | |
im.Save(psdPathAfterChange); | |
} | |
// Exposure layer adding | |
sourceFileName = dataDir + "PhotoExample.psd"; | |
psdPathAfterChange = dataDir + "PhotoExampleAddedExposure.psd"; | |
using (PsdImage im = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
var newlayer = im.AddExposureAdjustmentLayer(); | |
newlayer.Exposure = 10; | |
newlayer.Offset = -0.25f; | |
newlayer.GammaCorrection = 2f; | |
im.Save(psdPathAfterChange); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string dataDir = RunExamples.GetDataDir_PSD(); | |
// Photo Filter layer editing | |
string sourceFileName = dataDir + "PhotoFilterAdjustmentLayer.psd"; | |
string psdPathAfterChange = dataDir + "PhotoFilterAdjustmentLayerChanged.psd"; | |
using (var im = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
foreach (var layer in im.Layers) | |
{ | |
if (layer is PhotoFilterLayer) | |
{ | |
var photoLayer = (PhotoFilterLayer)layer; | |
photoLayer.Color = Color.FromArgb(255, 60, 60); | |
photoLayer.Density = 78; | |
photoLayer.PreserveLuminosity = false; | |
} | |
} | |
im.Save(psdPathAfterChange); | |
} | |
// Photo Filter layer adding | |
sourceFileName = dataDir + "PhotoExample.psd"; | |
psdPathAfterChange = dataDir + "PhotoExampleAddedPhotoFilter.psd"; | |
using (PsdImage im = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
var layer = im.AddPhotoFilterLayer(Color.FromArgb(25, 255, 35)); | |
im.Save(psdPathAfterChange); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFileName = dataDir + "LayerWithText.psd"; | |
var correctOpticalSize = new Size(127, 45); | |
var correctBoundBox = new Size(172, 62); | |
using (var im = (PsdImage)(Image.Load(sourceFileName))) | |
{ | |
var textLayer = (TextLayer)im.Layers[1]; | |
// Size of the layer is the size of the rendered area | |
var opticalSize = textLayer.Size; | |
// TextBoundBox is the maximum layer size for Text Layer. | |
// In this area PS will try to fit your text | |
var boundBox = textLayer.TextBoundBox; | |
if (opticalSize != correctOpticalSize || | |
boundBox.Size != correctBoundBox) | |
{ | |
throw new Exception("Assertion failed"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Load a PSD file as an image and cast it into PsdImage | |
using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "layers.psd")) | |
{ | |
// Create JPEG option class object, Set its properties and save image | |
var jpgOptions = new JpegOptions(); | |
psdImage.Save(dataDir + "MergePSDlayers_output.jpg", jpgOptions); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Add support of Fill layers: Pattern | |
string sourceFileName = dataDir + "PatternFillLayer.psd"; | |
string exportPath = dataDir + "PatternFillLayer_Edited.psd"; | |
double tolerance = 0.0001; | |
var im = (PsdImage)Image.Load(sourceFileName); | |
using (im) | |
{ | |
foreach (var layer in im.Layers) | |
{ | |
if (layer is FillLayer) | |
{ | |
FillLayer fillLayer = (FillLayer)layer; | |
PatternFillSettings fillSettings = (PatternFillSettings)fillLayer.FillSettings; | |
if (fillSettings.HorizontalOffset != -46 || | |
fillSettings.VerticalOffset != -45 || | |
fillSettings.PatternId != "a6818df2-7532-494e-9615-8fdd6b7f38e5" || | |
fillSettings.PatternName != "$$$/Presets/Patterns/OpticalSquares=Optical Squares" || | |
fillSettings.AlignWithLayer != true || | |
fillSettings.Linked != true || | |
fillSettings.PatternHeight != 64 || | |
fillSettings.PatternWidth != 64 || | |
fillSettings.PatternData.Length != 4096 || | |
Math.Abs(fillSettings.Scale - 50) > tolerance) | |
{ | |
throw new Exception("PSD Image was read wrong"); | |
} | |
// Editing | |
fillSettings.Scale = 300; | |
fillSettings.HorizontalOffset = 2; | |
fillSettings.VerticalOffset = -20; | |
fillSettings.PatternData = new int[] | |
{ | |
Color.Red.ToArgb(), Color.Blue.ToArgb(), Color.Blue.ToArgb(), | |
Color.Blue.ToArgb(), Color.Red.ToArgb(), Color.Blue.ToArgb(), | |
Color.Blue.ToArgb(), Color.Blue.ToArgb(), Color.Red.ToArgb() | |
}; | |
fillSettings.PatternHeight = 3; | |
fillSettings.PatternWidth = 3; | |
fillSettings.AlignWithLayer = false; | |
fillSettings.Linked = false; | |
fillSettings.PatternId = Guid.NewGuid().ToString(); | |
fillLayer.Update(); | |
break; | |
} | |
} | |
im.Save(exportPath); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Flatten whole PSD | |
string sourceFileName = dataDir + "ThreeRegularLayersSemiTransparent.psd"; | |
string exportPath = dataDir + "ThreeRegularLayersSemiTransparentFlattened.psd"; | |
using (var im = (PsdImage)(Image.Load(sourceFileName))) | |
{ | |
im.FlattenImage(); | |
im.Save(exportPath); | |
} | |
// Merge one layer in another | |
exportPath = dataDir + "ThreeRegularLayersSemiTransparentFlattenedLayerByLayer.psd"; | |
using (var im = (PsdImage)(Image.Load(sourceFileName))) | |
{ | |
var bottomLayer = im.Layers[0]; | |
var middleLayer = im.Layers[1]; | |
var topLayer = im.Layers[2]; | |
var layer1 = im.MergeLayers(bottomLayer, middleLayer); | |
var layer2 = im.MergeLayers(layer1, topLayer); | |
// Set up merged layers | |
im.Layers = new Layer[] { layer2 }; | |
im.Save(exportPath); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Add support of PSD export to PDF | |
string[] sourcesFiles = new string[] | |
{ | |
@"1.psd", | |
@"little.psb", | |
@"psb3.psb", | |
@"inRgb16.psd", | |
@"ALotOfElementTypes.psd", | |
@"ColorOverlayAndShadowAndMask.psd", | |
@"ThreeRegularLayersSemiTransparent.psd" | |
}; | |
for (int i = 0; i < sourcesFiles.Length; i++) | |
{ | |
string sourceFileName = sourcesFiles[i]; | |
using (PsdImage image = (PsdImage)Image.Load(dataDir + sourceFileName)) | |
{ | |
string outFileName = "PsdToPdf" + i + ".pdf"; | |
image.Save(dataDir + outFileName, new PdfOptions()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
using (PsdImage image = (PsdImage)Image.Load(dataDir + "example.psd")) | |
{ | |
image.Save(dataDir + "document.pdf", new PdfOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
using (PsdImage image = (PsdImage)Image.Load(dataDir + "clip.psd")) | |
{ | |
image.Save(dataDir + "output.pdf", new PdfOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFileName = dataDir + "text.psd"; | |
using (PsdImage image = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
string outFileName = dataDir + "text.pdf"; | |
image.Save(outFileName, new PdfOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFilePathPsd = dataDir + "2layers.psd"; | |
string outputFilePathPsb = dataDir + "ConvertFromPsd.psb"; | |
using (Image img = Image.Load(sourceFilePathPsd)) | |
{ | |
var options = new PsdOptions((PsdImage)img) { PsdVersion = PsdVersion.Psb }; | |
img.Save(outputFilePathPsb, options); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_PSD(); | |
// make changes in layer names and save it | |
using (var image = (PsdImage)Image.Load(dataDir + "Korean_layers.psd")) | |
{ | |
for (int i = 0; i < image.Layers.Length; i++) | |
{ | |
var layer = image.Layers[i]; | |
// set new value into DisplayName property | |
layer.DisplayName += "_changed"; | |
} | |
image.Save(dataDir + "Korean_layers_output.psd"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Rgb Channel Mixer | |
string sourceFileName = dataDir + "ChannelMixerAdjustmentLayerRgb.psd"; | |
string psdPathAfterChange = dataDir + "ChannelMixerAdjustmentLayerRgbChanged.psd"; | |
string pngExportPath = dataDir + "ChannelMixerAdjustmentLayerRgbChanged.png"; | |
using (var im = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
foreach (var layer in im.Layers) | |
{ | |
if (layer is RgbChannelMixerLayer) | |
{ | |
var rgbLayer = (RgbChannelMixerLayer)layer; | |
rgbLayer.RedChannel.Blue = 100; | |
rgbLayer.BlueChannel.Green = -100; | |
rgbLayer.GreenChannel.Constant = 50; | |
} | |
} | |
// Save PSD | |
im.Save(psdPathAfterChange); | |
// Save PNG | |
var saveOptions = new PngOptions(); | |
saveOptions.ColorType = PngColorType.TruecolorWithAlpha; | |
im.Save(pngExportPath, saveOptions); | |
} | |
// Cmyk Channel Mixer | |
sourceFileName = dataDir + "ChannelMixerAdjustmentLayerCmyk.psd"; | |
psdPathAfterChange = dataDir + "ChannelMixerAdjustmentLayerCmykChanged.psd"; | |
pngExportPath = dataDir + "ChannelMixerAdjustmentLayerCmykChanged.png"; | |
using (var im = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
foreach (var layer in im.Layers) | |
{ | |
if (layer is CmykChannelMixerLayer) | |
{ | |
var cmykLayer = (CmykChannelMixerLayer)layer; | |
cmykLayer.CyanChannel.Black = 20; | |
cmykLayer.MagentaChannel.Yellow = 50; | |
cmykLayer.YellowChannel.Cyan = -25; | |
cmykLayer.BlackChannel.Yellow = 25; | |
} | |
} | |
// Save PSD | |
im.Save(psdPathAfterChange); | |
// Save PNG | |
var saveOptions = new PngOptions(); | |
saveOptions.ColorType = PngColorType.TruecolorWithAlpha; | |
im.Save(pngExportPath, saveOptions); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Exposure layer editing | |
string sourceFileName = dataDir + "ExposureAdjustmentLayer.psd"; | |
string psdPathAfterChange = dataDir + "ExposureAdjustmentLayerChanged.psd"; | |
string pngExportPath = dataDir + "ExposureAdjustmentLayerChanged.png"; | |
using (var im = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
foreach (var layer in im.Layers) | |
{ | |
if (layer is ExposureLayer) | |
{ | |
var expLayer = (ExposureLayer)layer; | |
expLayer.Exposure = 2; | |
expLayer.Offset = -0.25f; | |
expLayer.GammaCorrection = 0.5f; | |
} | |
} | |
// Save PSD | |
im.Save(psdPathAfterChange); | |
// Save PNG | |
var saveOptions = new PngOptions(); | |
saveOptions.ColorType = PngColorType.TruecolorWithAlpha; | |
im.Save(pngExportPath, saveOptions); | |
} | |
// Exposure layer adding | |
sourceFileName = dataDir + "PhotoExample.psd"; | |
psdPathAfterChange = dataDir + "PhotoExampleAddedExposure.psd"; | |
pngExportPath = dataDir + "PhotoExampleAddedExposure.png"; | |
using (PsdImage im = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
var newlayer = im.AddExposureAdjustmentLayer(); | |
newlayer.Exposure = 2; | |
newlayer.Offset = -0.25f; | |
newlayer.GammaCorrection = 2f; | |
// Save PSD | |
im.Save(psdPathAfterChange); | |
// Save PNG | |
var saveOptions = new PngOptions(); | |
saveOptions.ColorType = PngColorType.TruecolorWithAlpha; | |
im.Save(pngExportPath, saveOptions); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Curves layer editing | |
string sourceFileName = dataDir + "CurvesAdjustmentLayer"; | |
string psdPathAfterChange = "CurvesAdjustmentLayerChanged"; | |
string pngExportPath = "CurvesAdjustmentLayerChanged"; | |
for (int j = 1; j < 2; j++) | |
{ | |
using (var im = (PsdImage)Image.Load(sourceFileName + j.ToString() + ".psd")) | |
{ | |
foreach (var layer in im.Layers) | |
{ | |
if (layer is CurvesLayer) | |
{ | |
var curvesLayer = (CurvesLayer)layer; | |
if (curvesLayer.IsDiscreteManagerUsed) | |
{ | |
var manager = (CurvesDiscreteManager)curvesLayer.GetCurvesManager(); | |
for (int i = 10; i < 50; i++) | |
{ | |
manager.SetValueInPosition(0, (byte)i, (byte)(15 + (i * 2))); | |
} | |
} | |
else | |
{ | |
var manager = (CurvesContinuousManager)curvesLayer.GetCurvesManager(); | |
manager.AddCurvePoint(0, 50, 100); | |
manager.AddCurvePoint(0, 150, 130); | |
} | |
} | |
} | |
// Save PSD | |
im.Save(psdPathAfterChange + j.ToString() + ".psd"); | |
// Save PNG | |
var saveOptions = new PngOptions(); | |
saveOptions.ColorType = PngColorType.TruecolorWithAlpha; | |
im.Save(pngExportPath + j.ToString() + ".png", saveOptions); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFile = dataDir + "text212.psd"; | |
string outputFile = dataDir + "Output_text212.psd"; | |
using (var img = (PsdImage)Image.Load(sourceFile)) | |
{ | |
TextLayer textLayer = (TextLayer)img.Layers[1]; | |
IText textData = textLayer.TextData; | |
ITextStyle defaultStyle = textData.ProducePortion().Style; | |
ITextParagraph defaultParagraph = textData.ProducePortion().Paragraph; | |
defaultStyle.FillColor = Color.DimGray; | |
defaultStyle.FontSize = 51; | |
textData.Items[1].Style.Strikethrough = true; | |
ITextPortion[] newPortions = textData.ProducePortions( | |
new string[] | |
{ | |
"E=mc", "2\r", "Bold", "Italic\r", | |
"Lowercasetext" | |
}, | |
defaultStyle, | |
defaultParagraph); | |
newPortions[0].Style.Underline = true; // edit text style "E=mc" | |
newPortions[1].Style.FontBaseline = FontBaseline.Superscript; // edit text style "2\r" | |
newPortions[2].Style.FauxBold = true; // edit text style "Bold" | |
newPortions[3].Style.FauxItalic = true; // edit text style "Italic\r" | |
newPortions[3].Style.BaselineShift = -25; // edit text style "Italic\r" | |
newPortions[4].Style.FontCaps = FontCaps.SmallCaps; // edit text style "Lowercasetext" | |
foreach (var newPortion in newPortions) | |
{ | |
textData.AddPortion(newPortion); | |
} | |
textData.UpdateLayerData(); | |
img.Save(outputFile); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFileName = dataDir + "LevelsAdjustmentLayer.psd"; | |
string psdPathAfterChange = dataDir + "LevelsAdjustmentLayerChanged.psd"; | |
string pngExportPath = dataDir + "LevelsAdjustmentLayerChanged.png"; | |
using (var im = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
foreach (var layer in im.Layers) | |
{ | |
if (layer is LevelsLayer) | |
{ | |
var levelsLayer = (LevelsLayer)layer; | |
var channel = levelsLayer.GetChannel(0); | |
channel.InputMidtoneLevel = 2.0f; | |
channel.InputShadowLevel = 10; | |
channel.InputHighlightLevel = 230; | |
channel.OutputShadowLevel = 20; | |
channel.OutputHighlightLevel = 200; | |
} | |
} | |
// Save PSD | |
im.Save(psdPathAfterChange); | |
// Save PNG | |
var saveOptions = new PngOptions(); | |
saveOptions.ColorType = PngColorType.TruecolorWithAlpha; | |
im.Save(pngExportPath, saveOptions); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string exportPath = dataDir + "TransformedTextExport.psd"; | |
string exportPathPng = dataDir + "TransformedTextExport.png"; | |
var im = (PsdImage)Image.Load(sourceFileName); | |
using (im) | |
{ | |
im.Save(exportPath); | |
im.Save(exportPathPng, new PngOptions() | |
{ | |
ColorType = PngColorType.Grayscale | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Implement correct Resize method for PSD files. | |
string sourceFileName = dataDir + "1.psd"; | |
string exportPathPsd = dataDir + "ResizeTest.psd"; | |
string exportPathPng = dataDir + "ResizeTest.png"; | |
using (RasterImage image = Image.Load(sourceFileName) as RasterImage) | |
{ | |
image.Resize(160, 120); | |
image.Save(exportPathPsd, new PsdOptions()); | |
image.Save(exportPathPng, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
//The following example demonstrates that reading and saving the Grayscale 16 bit PSD files works correctly and without an exception. | |
void SaveToPsdThenLoadAndSaveToPng( | |
string file, | |
ColorModes colorMode, | |
short channelBitsCount, | |
short channelsCount, | |
CompressionMethod compression, | |
int layerNumber) | |
{ | |
string filePath = file + ".psd"; | |
string postfix = colorMode.ToString() + channelBitsCount + "_" + channelsCount + "_" + compression; | |
string exportPath = file + postfix + ".psd"; | |
PsdOptions psdOptions = new PsdOptions() | |
{ | |
ColorMode = colorMode, | |
ChannelBitsCount = channelBitsCount, | |
ChannelsCount = channelsCount, | |
CompressionMethod = compression | |
}; | |
using (PsdImage image = (PsdImage)Image.Load(filePath)) | |
{ | |
RasterCachedImage raster = layerNumber >= 0 ? (RasterCachedImage)image.Layers[layerNumber] : image; | |
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 Pen(Color.DarkGray, 1), rect); | |
image.Save(exportPath, psdOptions); | |
} | |
string pngExportPath = Path.ChangeExtension(exportPath, "png"); | |
using (PsdImage image = (PsdImage)Image.Load(exportPath)) | |
{ | |
// Here should be no exception. | |
image.Save(pngExportPath, new PngOptions() { ColorType = PngColorType.GrayscaleWithAlpha }); | |
} | |
outputFilePathStack.Push(exportPath); | |
} | |
SaveToPsdThenLoadAndSaveToPng("grayscale5x5", ColorModes.Cmyk, 16, 5, CompressionMethod.RLE, 0); | |
SaveToPsdThenLoadAndSaveToPng("argb16bit_5x5", ColorModes.Grayscale, 16, 2, CompressionMethod.RLE, 0); | |
SaveToPsdThenLoadAndSaveToPng("argb16bit_5x5_no_layers", ColorModes.Grayscale, 16, 2, CompressionMethod.RLE, -1); | |
SaveToPsdThenLoadAndSaveToPng("argb8bit_5x5", ColorModes.Grayscale, 16, 2, CompressionMethod.RLE, 0); | |
SaveToPsdThenLoadAndSaveToPng("argb8bit_5x5_no_layers", ColorModes.Grayscale, 16, 2, CompressionMethod.RLE, -1); | |
SaveToPsdThenLoadAndSaveToPng("cmyk16bit_5x5_no_layers", ColorModes.Grayscale, 16, 2, CompressionMethod.RLE, -1); | |
SaveToPsdThenLoadAndSaveToPng("index8bit_5x5", ColorModes.Grayscale, 16, 2, CompressionMethod.RLE, -1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
//The following example demonstrates that reading and saving the Grayscale 16 bit PSD files to 8 bit per channel Grayscale works correctly and without an exception. | |
string sourceFilePath = "grayscale16bit.psd"; | |
string exportFilePath = "grayscale16bit_Grayscale8_2_RLE.psd"; | |
PsdOptions psdOptions = new PsdOptions() | |
{ | |
ColorMode = ColorModes.Grayscale, | |
ChannelBitsCount = 8, | |
ChannelsCount = 2 | |
}; | |
using (PsdImage image = (PsdImage)Image.Load(sourceFilePath)) | |
{ | |
RasterCachedImage raster = image.Layers[0]; | |
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 Pen(Color.DarkGray, 1), rect); | |
image.Save(exportFilePath, psdOptions); | |
} | |
string pngExportPath = Path.ChangeExtension(exportFilePath, "png"); | |
using (PsdImage image = (PsdImage)Image.Load(exportFilePath)) | |
{ | |
// Here should be no exception. | |
image.Save(pngExportPath, new PngOptions() { ColorType = PngColorType.GrayscaleWithAlpha }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
//The following example demonstrates that reading and saving the Grayscale 16 bit PSD files to 16bit per channel RGB works correctly and without an exception. | |
string sourceFilePath = "grayscale5x5.psd"; | |
string exportFilePath = "rgb16bit5x5.psd"; | |
PsdOptions psdOptions = new PsdOptions() | |
{ | |
ColorMode = ColorModes.Rgb, | |
ChannelBitsCount = 16, | |
ChannelsCount = 4 | |
}; | |
using (PsdImage image = (PsdImage)Image.Load(sourceFilePath)) | |
{ | |
RasterCachedImage raster = image.Layers[0]; | |
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 Pen(Color.DarkGray, 1), rect); | |
image.Save(exportFilePath, psdOptions); | |
} | |
string pngExportPath = Path.ChangeExtension(exportFilePath, "png"); | |
using (PsdImage image = (PsdImage)Image.Load(exportFilePath)) | |
{ | |
// Here should be no exception. | |
image.Save(pngExportPath, new PngOptions() { ColorType = PngColorType.GrayscaleWithAlpha }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string exportPath = dataDir + "OneLayer_Edited.psd"; | |
int leftPos = 99; | |
int topPos = 47; | |
var im = (PsdImage)Image.Load(sourceFileName); | |
using (im) | |
{ | |
im.AddTextLayer("Some text", new Rectangle(leftPos, topPos, 99, 47)); | |
TextLayer textLayer = (TextLayer)im.Layers[1]; | |
if (textLayer.Left != leftPos || textLayer.Top != topPos) | |
{ | |
throw new Exception("Was created incorrect Text Layer"); | |
} | |
im.Save(exportPath); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string exportPath = dataDir + "SheetColorHighlightExampleChanged.psd"; | |
// Load a PSD file as an image and cast it into PsdImage | |
using (var im = (PsdImage)(Image.Load(sourceFileName))) | |
{ | |
var layer1 = im.Layers[0]; | |
var layer2 = im.Layers[1]; | |
if (layer1.SheetColorHighlight != SheetColorHighlightEnum.Violet || | |
layer2.SheetColorHighlight != SheetColorHighlightEnum.Orange) | |
{ | |
throw new Exception("Assertion failed"); | |
} | |
layer1.SheetColorHighlight = SheetColorHighlightEnum.Yellow; | |
im.Save(exportPath); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_PSD(); | |
// Implement rendering of Stroke effect with Color Fill for export | |
string sourceFileName = dataDir + "StrokeComplex.psd"; | |
string exportPath = dataDir + "StrokeComplexRendering.psd"; | |
string exportPathPng = dataDir + "StrokeComplexRendering.png"; | |
var loadOptions = new PsdLoadOptions() | |
{ | |
LoadEffectsResource = true | |
}; | |
using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) | |
{ | |
for (int i = 0; i < im.Layers.Length; i++) | |
{ | |
var effect = (StrokeEffect)im.Layers[i].BlendingOptions.Effects[0]; | |
var settings = (ColorFillSettings)effect.FillSettings; | |
settings.Color = Color.DeepPink; | |
} | |
// Save psd | |
im.Save(exportPath, new PsdOptions()); | |
// Save png | |
im.Save(exportPathPng, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFileName = dataDir + "layers.psd"; | |
string output = dataDir + "layers.png"; | |
using (PsdImage image = (PsdImage)Image.Load(sourceFileName, | |
new ImageLoadOptions.PsdLoadOptions() | |
{ | |
LoadEffectsResource = true, | |
UseDiskForLoadEffectsResource = true | |
})) | |
{ | |
Debug.Assert(image.Layers[2] != null, "Layer with effects resource was not recognized"); | |
image.Save(output, new ImageOptions.PngOptions() | |
{ | |
ColorType = | |
FileFormats.Png | |
.PngColorType | |
.TruecolorWithAlpha | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Channel Mixer Adjustment Layer | |
string sourceFileName1 = dataDir + "ChannelMixerAdjustmentLayer.psd"; | |
string exportPath1 = dataDir + "ChannelMixerAdjustmentLayerChanged.psd"; | |
using (var im = (PsdImage)(Image.Load(sourceFileName1))) | |
{ | |
for (int i = 0; i < im.Layers.Length; i++) | |
{ | |
var adjustmentLayer = im.Layers[i] as AdjustmentLayer; | |
if (adjustmentLayer != null) | |
{ | |
adjustmentLayer.MergeLayerTo(im.Layers[0]); | |
} | |
} | |
// Save PSD | |
im.Save(exportPath1); | |
} | |
// Levels adjustment layer | |
var sourceFileName2 = dataDir + "LevelsAdjustmentLayerRgb.psd"; | |
var exportPath2 = dataDir + "LevelsAdjustmentLayerRgbChanged.psd"; | |
using (var im = (PsdImage)(Image.Load(sourceFileName2))) | |
{ | |
for (int i = 0; i < im.Layers.Length; i++) | |
{ | |
var adjustmentLayer = im.Layers[i] as AdjustmentLayer; | |
if (adjustmentLayer != null) | |
{ | |
adjustmentLayer.MergeLayerTo(im.Layers[0]); | |
} | |
} | |
// Save PSD | |
im.Save(exportPath2); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Exposure layer editing | |
// Export of the psd with complex clipping mask | |
string sourceFileName = dataDir + "ClippingMaskComplex.psd"; | |
string exportPath = dataDir + "ClippingMaskComplex.png"; | |
using (var im = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
// Export to PNG | |
var saveOptions = new PngOptions(); | |
saveOptions.ColorType = PngColorType.TruecolorWithAlpha; | |
im.Save(exportPath, saveOptions); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
using (PsdImage image = (PsdImage)Image.Load(baseFolder + "cub16bit_cmyk.psd")) | |
{ | |
RasterCachedImage raster = image.Layers[0]; | |
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 Pen(Color.DarkGray, 1), rect); | |
image.Save(output + "output.psd"); | |
image.Save(output + "output.png", new PngOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Support of GdFlResource | |
string sourceFileName = dataDir + "ComplexGradientFillLayer.psd"; | |
string exportPath = dataDir + "ComplexGradientFillLayer_after.psd"; | |
var im = (FileFormats.Psd.PsdImage)Image.Load(sourceFileName); | |
using (im) | |
{ | |
foreach (var layer in im.Layers) | |
{ | |
if (layer is FillLayer) | |
{ | |
var fillLayer = (FillLayer)layer; | |
var resources = fillLayer.Resources; | |
foreach (var res in resources) | |
{ | |
if (res is GdFlResource) | |
{ | |
// Reading | |
var resource = (GdFlResource)res; | |
if (resource.AlignWithLayer != false || | |
(Math.Abs(resource.Angle - 45.0) > 0.001) || | |
resource.Dither != true || | |
resource.Reverse != false || | |
resource.Color != Color.Empty || | |
Math.Abs(resource.HorizontalOffset - (-39)) > 0.001 || | |
Math.Abs(resource.VerticalOffset - (-5)) > 0.001 || | |
resource.TransparencyPoints.Length != 3 || | |
resource.ColorPoints.Length != 2) | |
{ | |
throw new Exception("Resource Parameters were read wrong"); | |
} | |
var transparencyPoints = resource.TransparencyPoints; | |
if (Math.Abs(100.0 - transparencyPoints[0].Opacity) > 0.25 || | |
transparencyPoints[0].Location != 0 || | |
transparencyPoints[0].MedianPointLocation != 50 || | |
Math.Abs(50.0 - transparencyPoints[1].Opacity) > 0.25 || | |
transparencyPoints[1].Location != 2048 || | |
transparencyPoints[1].MedianPointLocation != 50 || | |
Math.Abs(100.0 - transparencyPoints[2].Opacity) > 0.25 || | |
transparencyPoints[2].Location != 4096 || | |
transparencyPoints[2].MedianPointLocation != 50) | |
{ | |
throw new Exception("Gradient Transparency Points were read Wrong"); | |
} | |
var colorPoints = resource.ColorPoints; | |
if (colorPoints[0].Color != Color.FromArgb(203, 64, 140) || | |
colorPoints[0].Location != 0 || | |
colorPoints[0].MedianPointLocation != 50 || | |
colorPoints[1].Color != Color.FromArgb(203, 0, 0) || | |
colorPoints[1].Location != 4096 || | |
colorPoints[1].MedianPointLocation != 50) | |
{ | |
throw new Exception("Gradient Color Points were read Wrong"); | |
} | |
// Editing | |
resource.Angle = 30.0; | |
resource.Dither = false; | |
resource.AlignWithLayer = true; | |
resource.Reverse = true; | |
resource.HorizontalOffset = 25; | |
resource.VerticalOffset = -15; | |
var newColorPoints = new List<IGradientColorPoint>(resource.ColorPoints); | |
var | |
newTransparencyPoints = new | |
List<IGradientTransparencyPoint>(resource.TransparencyPoints); | |
newColorPoints.Add(new GradientColorPoint() | |
{ | |
Color = Color.Violet, | |
Location = 4096, | |
MedianPointLocation = 75 | |
}); | |
colorPoints[1].Location = 3000; | |
newTransparencyPoints.Add(new GradientTransparencyPoint() | |
{ | |
Opacity = 80.0, | |
Location = 4096, | |
MedianPointLocation = 25 | |
}); | |
transparencyPoints[2].Location = 3000; | |
resource.ColorPoints = newColorPoints.ToArray(); | |
resource.TransparencyPoints = newTransparencyPoints.ToArray(); | |
im.Save(exportPath); | |
} | |
break; | |
} | |
break; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string destName = dataDir + "innershadow_out.psd"; | |
var loadOptions = new PsdLoadOptions() | |
{ | |
LoadEffectsResource = true | |
}; | |
// Load an existing image into an instance of PsdImage class | |
using (var image = (PsdImage)Image.Load(sourceFile, loadOptions)) | |
{ | |
var layer = image.Layers[image.Layers.Length - 1]; | |
var shadowEffect = (IShadowEffect)layer.BlendingOptions.Effects[0]; | |
shadowEffect.Color = Color.Green; | |
shadowEffect.Opacity = 128; | |
shadowEffect.Distance = 1; | |
shadowEffect.UseGlobalLight = false; | |
shadowEffect.Size = 2; | |
shadowEffect.Angle = 45; | |
shadowEffect.Spread = 50; | |
shadowEffect.Noise = 5; | |
image.Save(destName, new PsdOptions(image)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
void AssertAreEqual(object expected, object actual) | |
{ | |
if (!object.Equals(expected, actual)) | |
{ | |
throw new FormatException( | |
string.Format("Actual value {0} are not equal to expected {1}.", actual, expected)); | |
} | |
} | |
string srcFile = baseFolder + "A.psd"; | |
string outputFile = output + "output.psd"; | |
using (var psdImage = (PsdImage)Image.Load(srcFile)) | |
{ | |
var textLayer = (TextLayer)psdImage.Layers[1]; | |
textLayer.UpdateText("abc"); | |
psdImage.Save(outputFile); | |
} | |
// Check values | |
using (var srcImage = (PsdImage)Image.Load(srcFile)) | |
{ | |
var srcTextLayer = (TextLayer)srcImage.Layers[1]; | |
var etalonStyle = srcTextLayer.TextData.Items[0].Style; | |
using (var outImage = (PsdImage)Image.Load(outputFile)) | |
{ | |
var outTextLayer = (TextLayer)outImage.Layers[1]; | |
var resultStyle = outTextLayer.TextData.Items[0].Style; | |
AssertAreEqual(etalonStyle.AutoLeading, resultStyle.AutoLeading); | |
AssertAreEqual(etalonStyle.FontIndex, resultStyle.FontIndex); | |
AssertAreEqual(etalonStyle.Underline, resultStyle.Underline); | |
AssertAreEqual(etalonStyle.Strikethrough, resultStyle.Strikethrough); | |
AssertAreEqual(etalonStyle.AutoKerning, resultStyle.AutoKerning); | |
AssertAreEqual(etalonStyle.StandardLigatures, resultStyle.StandardLigatures); | |
AssertAreEqual(etalonStyle.DiscretionaryLigatures, resultStyle.DiscretionaryLigatures); | |
AssertAreEqual(etalonStyle.ContextualAlternates, resultStyle.ContextualAlternates); | |
AssertAreEqual(etalonStyle.LanguageIndex, resultStyle.LanguageIndex); | |
AssertAreEqual(etalonStyle.VerticalScale, resultStyle.VerticalScale); | |
AssertAreEqual(etalonStyle.HorizontalScale, resultStyle.HorizontalScale); | |
AssertAreEqual(etalonStyle.Fractions, resultStyle.Fractions); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Export of the psd with complex mask | |
string sourceFileName = dataDir + "MaskComplex.psd"; | |
string exportPath = dataDir + "MaskComplex.png"; | |
using (var im = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
// Export to PNG | |
var saveOptions = new PngOptions(); | |
saveOptions.ColorType = PngColorType.TruecolorWithAlpha; | |
im.Save(exportPath, saveOptions); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string exportPath = dataDir + "DifferentLayerMasks_Export.psd"; | |
string exportPathPng = dataDir + "DifferentLayerMasks_Export.png"; | |
// reading | |
using (PsdImage image = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
// make changes to the vector path points | |
foreach (var layer in image.Layers) | |
{ | |
foreach (var layerResource in layer.Resources) | |
{ | |
var resource = layerResource as VectorPathDataResource; | |
if (resource != null) | |
{ | |
foreach (var pathRecord in resource.Paths) | |
{ | |
var bezierKnotRecord = pathRecord as BezierKnotRecord; | |
if (bezierKnotRecord != null) | |
{ | |
Point p0 = bezierKnotRecord.Points[0]; | |
bezierKnotRecord.Points[0] = bezierKnotRecord.Points[2]; | |
bezierKnotRecord.Points[2] = p0; | |
break; | |
} | |
} | |
} | |
} | |
} | |
// exporting | |
image.Save(exportPath); | |
image.Save(exportPathPng, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
{ | |
Layer[] layers = psd.Layers; | |
// link all layers in one linked group | |
short layersLinkGroupId = psd.LinkedLayersManager.LinkLayers(layers); | |
// gets id for one layer | |
short linkGroupId = psd.LinkedLayersManager.GetLinkGroupId(layers[0]); | |
if (layersLinkGroupId != linkGroupId) | |
{ | |
throw new Exception("layersLinkGroupId and linkGroupId are not equal."); | |
} | |
// gets all linked layers by link group id. | |
Layer[] linkedLayers = psd.LinkedLayersManager.GetLayersByLinkGroupId(linkGroupId); | |
// unlink each layer from group | |
foreach (var linkedLayer in linkedLayers) | |
{ | |
psd.LinkedLayersManager.UnlinkLayer(linkedLayer); | |
} | |
// retrieves NULL for a link group ID that has no layers in the group. | |
linkedLayers = psd.LinkedLayersManager.GetLayersByLinkGroupId(linkGroupId); | |
if (linkedLayers != null) | |
{ | |
throw new Exception("The linkedLayers field is not NULL."); | |
} | |
psd.Save(dataDir + "LinkedLayerexample_output.psd"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Support of PtFlResource | |
string sourceFileName = dataDir + "PatternFillLayer.psd"; | |
string exportPath = dataDir + "PtFlResource_Edited.psd"; | |
double tolerance = 0.0001; | |
var im = (PsdImage)Image.Load(sourceFileName); | |
using (im) | |
{ | |
foreach (var layer in im.Layers) | |
{ | |
if (layer is FillLayer) | |
{ | |
var fillLayer = (FillLayer)layer; | |
var resources = fillLayer.Resources; | |
foreach (var res in resources) | |
{ | |
if (res is PtFlResource) | |
{ | |
// Reading | |
PtFlResource resource = (PtFlResource)res; | |
if ( | |
resource.Offset.X != -46 || | |
resource.Offset.Y != -45 || | |
resource.PatternId != "a6818df2-7532-494e-9615-8fdd6b7f38e5\0" || | |
resource.PatternName != "$$$/Presets/Patterns/OpticalSquares=Optical Squares\0" || | |
resource.AlignWithLayer != true || | |
resource.IsLinkedWithLayer != true || | |
!(Math.Abs(resource.Scale - 50) < tolerance)) | |
{ | |
throw new Exception("PtFl Resource was read incorrect"); | |
} | |
// Editing | |
resource.Offset = new Point(-11, 13); | |
resource.Scale = 200; | |
resource.AlignWithLayer = false; | |
resource.IsLinkedWithLayer = false; | |
fillLayer.Resources = fillLayer.Resources; | |
// We haven't pattern data in PattResource, so we can add it. | |
var fillSettings = (PatternFillSettings)fillLayer.FillSettings; | |
fillSettings.PatternData = new int[] | |
{ | |
Color.Black.ToArgb(), | |
Color.White.ToArgb(), | |
Color.White.ToArgb(), | |
Color.White.ToArgb(), | |
}; | |
fillSettings.PatternHeight = 1; | |
fillSettings.PatternWidth = 4; | |
fillSettings.PatternName = "$$$/Presets/Patterns/VerticalLine=Vertical Line New\0"; | |
fillSettings.PatternId = Guid.NewGuid().ToString() + "\0"; | |
fillLayer.Update(); | |
} | |
break; | |
} | |
break; | |
} | |
} | |
im.Save(exportPath); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Support of RGB Color mode with 16bits/channel (64 bits per color) | |
string sourceFileName = dataDir + "inRgb16.psd"; | |
string outputFilePathJpg = dataDir + "outRgb16.jpg"; | |
string outputFilePathPsd = dataDir + "outRgb16.psd"; | |
PsdLoadOptions options = new PsdLoadOptions(); | |
using (PsdImage image = (PsdImage)Image.Load(sourceFileName, options)) | |
{ | |
image.Save(outputFilePathPsd, new PsdOptions(image)); | |
image.Save(outputFilePathJpg, new JpegOptions() | |
{ | |
Quality = 100 | |
}); | |
} | |
// Files must be opened without exception and must be readable for Photoshop | |
using (Image image = Image.Load(outputFilePathPsd)) | |
{ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
var pngPath = dataDir + "RotateFlipTest2617.png"; | |
var psdPath = dataDir + "RotateFlipTest2617.psd"; | |
var flipType = RotateFlipType.Rotate270FlipXY; | |
using (var im = (PsdImage)(Image.Load(sourceFile))) | |
{ | |
im.RotateFlip(flipType); | |
im.Save(pngPath, new PngOptions() | |
{ | |
ColorType = PngColorType.TruecolorWithAlpha | |
}); | |
im.Save(psdPath); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
using (var image = (PsdImage)Image.Load(dataDir + "FillLayerGradient.psd")) | |
{ | |
// getting a fill layer | |
FillLayer fillLayer = null; | |
foreach (var layer in image.Layers) | |
{ | |
fillLayer = layer as FillLayer; | |
if (fillLayer != null) | |
{ | |
break; | |
} | |
} | |
var settings = fillLayer.FillSettings as IGradientFillSettings; | |
// update scale value | |
settings.Scale = 200; | |
fillLayer.Update(); // Updates pixels data | |
image.Save(dataDir + "scaledImage.png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFileName = dataDir + "ColorFillLayer.psd"; | |
string exportPath = dataDir + "SoCoResource_Edited.psd"; | |
var im = (PsdImage)Image.Load(sourceFileName); | |
using (im) | |
{ | |
foreach (var layer in im.Layers) | |
{ | |
if (layer is FillLayer) | |
{ | |
var fillLayer = (FillLayer)layer; | |
foreach (var resource in fillLayer.Resources) | |
{ | |
if (resource is SoCoResource) | |
{ | |
var socoResource = (SoCoResource)resource; | |
if (socoResource.Color != Color.FromArgb(63, 83, 141)) | |
{ | |
throw new Exception("Color from SoCoResource was read wrong"); | |
} | |
socoResource.Color = Color.Red; | |
break; | |
} | |
} | |
break; | |
} | |
im.Save(exportPath); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
void AssertAreEqual(object actual, object expected) | |
{ | |
var areEqual = object.Equals(actual, expected); | |
if (!areEqual && actual is Array && expected is Array) | |
{ | |
var actualArray = (Array)actual; | |
var expectedArray = (Array)actual; | |
if (actualArray.Length == expectedArray.Length) | |
{ | |
for (int i = 0; i < actualArray.Length; i++) | |
{ | |
if (!object.Equals(actualArray.GetValue(i), expectedArray.GetValue(i))) | |
{ | |
break; | |
} | |
} | |
areEqual = true; | |
} | |
} | |
if (!areEqual) | |
{ | |
throw new FormatException( | |
string.Format("Actual value {0} are not equal to expected {1}.", actual, expected)); | |
} | |
} | |
// This example demonstrates how to update the external or embedded smart object layer using these methods: | |
// RelinkToFile, UpdateModifiedContent, ExportContents | |
ExampleOfUpdatingSmartObjectLayer("rgb8_2x2_linked2.psd", 0x53, 0, 0, 2, 2, FileFormat.Png); | |
ExampleOfUpdatingSmartObjectLayer("r-embedded-png.psd", 0x207, 0, 0, 0xb, 0x10, FileFormat.Png); | |
void ExampleOfUpdatingSmartObjectLayer( | |
string filePath, | |
int contentsLength, | |
int left, | |
int top, | |
int right, | |
int bottom, | |
FileFormat format) | |
{ | |
// This example demonstrates how to change the smart object layer in the PSD file and export / update its contents. | |
string fileName = Path.GetFileNameWithoutExtension(filePath); | |
string dataDir = output + "updating_output\\"; | |
filePath = baseFolder + filePath; | |
string pngOutputPath = dataDir + fileName + "_modified.png"; | |
string png2OutputPath = dataDir + fileName + "_updated_modified.png"; | |
string psd2OutputPath = dataDir + fileName + "_updated_modified.psd"; | |
string exportPath = dataDir + fileName + "_exported." + GetFormatExt(format); | |
using (PsdImage image = (PsdImage)Image.Load(filePath)) | |
{ | |
var smartObjectLayer = (SmartObjectLayer)image.Layers[0]; | |
var contentType = smartObjectLayer.ContentType; | |
AssertAreEqual(contentsLength, smartObjectLayer.Contents.Length); | |
AssertAreEqual(left, smartObjectLayer.ContentsBounds.Left); | |
AssertAreEqual(top, smartObjectLayer.ContentsBounds.Top); | |
AssertAreEqual(right, smartObjectLayer.ContentsBounds.Right); | |
AssertAreEqual(bottom, smartObjectLayer.ContentsBounds.Bottom); | |
if (contentType == SmartObjectType.AvailableLinked) | |
{ | |
Directory.CreateDirectory(Path.GetDirectoryName(exportPath)); | |
// Let's export the external smart object image from the PSD smart object layer to a new location | |
// because we are going to modify it. | |
smartObjectLayer.ExportContents(exportPath); | |
smartObjectLayer.RelinkToFile(exportPath); | |
} | |
// Let's invert the content of the smart object: inner (not cached) image | |
using (var innerImage = (RasterImage)smartObjectLayer.LoadContents(new LoadOptions())) | |
{ | |
InvertImage(innerImage); | |
using (var stream = new MemoryStream()) | |
{ | |
innerImage.Save(stream); | |
smartObjectLayer.Contents = stream.ToArray(); | |
} | |
} | |
// Let's check whether the modified content does not affect rendering yet. | |
image.Save(pngOutputPath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); | |
smartObjectLayer.UpdateModifiedContent(); | |
// Let's check whether the updated content affects rendering and the psd image is saved correctly | |
image.Save(psd2OutputPath, new PsdOptions(image)); | |
image.Save(png2OutputPath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); | |
} | |
} | |
// This example demonstrates how to convert the embedded smart object to external linked contents using the ConvertToLinked method. | |
ExampleOfEmbeddedSmartObjectLayerToLinkedConversion("new_panama-papers-4.psd", 0x10caa, 0, 0, 0x280, 0x169, FileFormat.Jpeg); | |
ExampleOfEmbeddedSmartObjectLayerToLinkedConversion("r3-embedded.psd", 0x207, 0, 0, 0xb, 0x10, FileFormat.Png); | |
ExampleOfEmbeddedSmartObjectLayerToLinkedConversion("r-embedded-tiff.psd", 0xca94, 0, 0, 0xb, 0x10, FileFormat.Tiff); | |
ExampleOfEmbeddedSmartObjectLayerToLinkedConversion("r-embedded-bmp.psd", 0x278, 0, 0, 0xb, 0x10, FileFormat.Bmp); | |
ExampleOfEmbeddedSmartObjectLayerToLinkedConversion("r-embedded-gif.psd", 0x3ec, 0, 0, 0xb, 0x10, FileFormat.Gif); | |
ExampleOfEmbeddedSmartObjectLayerToLinkedConversion("r-embedded-jpeg.psd", 0x327, 0, 0, 0xb, 0x10, FileFormat.Jpeg); | |
ExampleOfEmbeddedSmartObjectLayerToLinkedConversion("r-embedded-jpeg2000.psd", 0x519f, 0, 0, 0xb, 0x10, FileFormat.Jpeg2000); | |
ExampleOfEmbeddedSmartObjectLayerToLinkedConversion("r-embedded-psd.psd", 0xc074, 0, 0, 0xb, 0x10, FileFormat.Psd); | |
ExampleOfEmbeddedSmartObjectLayerToLinkedConversion("r-embedded-png.psd", 0x207, 0, 0, 0xb, 0x10, FileFormat.Png); | |
void ExampleOfEmbeddedSmartObjectLayerToLinkedConversion( | |
string filePath, | |
int contentsLength, | |
int left, | |
int top, | |
int right, | |
int bottom, | |
FileFormat format) | |
{ | |
// This demonstrates how to convert an embedded smart object layer in the PSD file to external one. | |
var formatExt = GetFormatExt(format); | |
string fileName = Path.GetFileNameWithoutExtension(filePath); | |
string dataDir = output + "to_linked_output\\"; | |
filePath = baseFolder + filePath; | |
string pngOutputPath = dataDir + fileName + "_to_external.png"; | |
string psdOutputPath = dataDir + fileName + "_to_external.psd"; | |
string externalPath = dataDir + fileName + "_external." + formatExt; | |
using (PsdImage image = (PsdImage)Image.Load(filePath)) | |
{ | |
Directory.CreateDirectory(Path.GetDirectoryName(externalPath)); | |
var smartObjectLayer = (SmartObjectLayer)image.Layers[0]; | |
smartObjectLayer.ConvertToLinked(externalPath); | |
AssertAreEqual(contentsLength, smartObjectLayer.Contents.Length); | |
AssertAreEqual(left, smartObjectLayer.ContentsBounds.Left); | |
AssertAreEqual(top, smartObjectLayer.ContentsBounds.Top); | |
AssertAreEqual(right, smartObjectLayer.ContentsBounds.Right); | |
AssertAreEqual(bottom, smartObjectLayer.ContentsBounds.Bottom); | |
AssertAreEqual(SmartObjectType.AvailableLinked, smartObjectLayer.ContentType); | |
// Let's check if the converted image is saved correctly | |
image.Save(psdOutputPath, new PsdOptions(image)); | |
image.Save(pngOutputPath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); | |
} | |
using (PsdImage image = (PsdImage)Image.Load(psdOutputPath)) | |
{ | |
var smartObjectLayer = (SmartObjectLayer)image.Layers[0]; | |
AssertAreEqual(contentsLength, smartObjectLayer.Contents.Length); | |
AssertAreEqual(left, smartObjectLayer.ContentsBounds.Left); | |
AssertAreEqual(top, smartObjectLayer.ContentsBounds.Top); | |
AssertAreEqual(right, smartObjectLayer.ContentsBounds.Right); | |
AssertAreEqual(bottom, smartObjectLayer.ContentsBounds.Bottom); | |
AssertAreEqual(SmartObjectType.AvailableLinked, smartObjectLayer.ContentType); | |
} | |
} | |
// This example demonstrates how to embed one external smart object layer or all linked layers in the PSD file using the EmbedLinked method. | |
ExampleOfLinkedSmartObjectLayerToEmbeddedConversion("rgb8_2x2_linked.psd", 0x53, 0, 0, 2, 2, FileFormat.Png); | |
ExampleOfLinkedSmartObjectLayerToEmbeddedConversion("rgb8_2x2_linked2.psd", 0x53, 0, 0, 2, 2, FileFormat.Png); | |
void ExampleOfLinkedSmartObjectLayerToEmbeddedConversion( | |
string filePath, | |
int contentsLength, | |
int left, | |
int top, | |
int right, | |
int bottom, | |
FileFormat format) | |
{ | |
string fileName = Path.GetFileNameWithoutExtension(filePath); | |
string dataDir = output + "to_embedded_output\\"; | |
filePath = baseFolder + filePath; | |
string pngOutputPath = dataDir + fileName + "_to_embedded.png"; | |
string psdOutputPath = dataDir + fileName + "_to_embedded.psd"; | |
using (PsdImage image = (PsdImage)Image.Load(filePath)) | |
{ | |
var smartObjectLayer0 = (SmartObjectLayer)image.Layers[0]; | |
smartObjectLayer0.EmbedLinked(); | |
AssertAreEqual(contentsLength, smartObjectLayer0.Contents.Length); | |
AssertAreEqual(left, smartObjectLayer0.ContentsBounds.Left); | |
AssertAreEqual(top, smartObjectLayer0.ContentsBounds.Top); | |
AssertAreEqual(right, smartObjectLayer0.ContentsBounds.Right); | |
AssertAreEqual(bottom, smartObjectLayer0.ContentsBounds.Bottom); | |
if (image.Layers.Length >= 2) | |
{ | |
var smartObjectLayer1 = (SmartObjectLayer)image.Layers[1]; | |
AssertAreEqual(SmartObjectType.Embedded, smartObjectLayer0.ContentType); | |
AssertAreEqual(SmartObjectType.AvailableLinked, smartObjectLayer1.ContentType); | |
image.SmartObjectProvider.EmbedAllLinked(); | |
foreach (Layer layer in image.Layers) | |
{ | |
var smartLayer = layer as SmartObjectLayer; | |
if (smartLayer != null) | |
{ | |
AssertAreEqual(SmartObjectType.Embedded, smartLayer.ContentType); | |
} | |
} | |
} | |
Directory.CreateDirectory(Path.GetDirectoryName(psdOutputPath)); | |
// Let's check if the converted image is saved correctly | |
image.Save(psdOutputPath, new PsdOptions(image)); | |
image.Save(pngOutputPath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); | |
} | |
using (PsdImage image = (PsdImage)Image.Load(psdOutputPath)) | |
{ | |
var smartObjectLayer = (SmartObjectLayer)image.Layers[0]; | |
AssertAreEqual(contentsLength, smartObjectLayer.Contents.Length); | |
AssertAreEqual(left, smartObjectLayer.ContentsBounds.Left); | |
AssertAreEqual(top, smartObjectLayer.ContentsBounds.Top); | |
AssertAreEqual(right, smartObjectLayer.ContentsBounds.Right); | |
AssertAreEqual(bottom, smartObjectLayer.ContentsBounds.Bottom); | |
AssertAreEqual(SmartObjectType.Embedded, smartObjectLayer.ContentType); | |
} | |
} | |
// This example demonstrates how to change the Adobe® Photoshop® external smart object layer and export / update its contents | |
// using the ExportContents and ReplaceContents methods. | |
ExampleOfExternalSmartObjectLayerSupport("rgb8_2x2_linked.psd", 0x53, 0, 0, 2, 2, FileFormat.Png); | |
ExampleOfExternalSmartObjectLayerSupport("rgb8_2x2_linked2.psd", 0x4aea, 0, 0, 10, 10, FileFormat.Psd); | |
void ExampleOfExternalSmartObjectLayerSupport(string filePath, int contentsLength, int left, int top, int right, int bottom, FileFormat format) | |
{ | |
string formatExt = GetFormatExt(format); | |
string fileName = Path.GetFileNameWithoutExtension(filePath); | |
string dataDir = output + "external_support_output\\"; | |
filePath = baseFolder + filePath; | |
string pngOutputPath = dataDir + fileName + ".png"; | |
string psdOutputPath = dataDir + fileName + ".psd"; | |
string linkOutputPath = dataDir + fileName + "_inverted." + formatExt; | |
string png2OutputPath = dataDir + fileName + "_updated.png"; | |
string psd2OutputPath = dataDir + fileName + "_updated.psd"; | |
string exportPath = dataDir + fileName + "_export." + formatExt; | |
using (PsdImage image = (PsdImage)Image.Load(filePath)) | |
{ | |
var smartObjectLayer = (SmartObjectLayer)image.Layers[image.Layers.Length - 1]; | |
AssertAreEqual(left, smartObjectLayer.ContentsBounds.Left); | |
AssertAreEqual(top, smartObjectLayer.ContentsBounds.Top); | |
AssertAreEqual(right, smartObjectLayer.ContentsBounds.Right); | |
AssertAreEqual(bottom, smartObjectLayer.ContentsBounds.Bottom); | |
AssertAreEqual(contentsLength, smartObjectLayer.Contents.Length); | |
AssertAreEqual(SmartObjectType.AvailableLinked, smartObjectLayer.ContentType); | |
Directory.CreateDirectory(Path.GetDirectoryName(exportPath)); | |
// Let's export the linked smart object image from the PSD smart object layer | |
smartObjectLayer.ExportContents(exportPath); | |
// Let's check if the original image isz saved correctly | |
image.Save(psdOutputPath, new PsdOptions(image)); | |
image.Save(pngOutputPath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); | |
using (var innerImage = (RasterImage)smartObjectLayer.LoadContents(null)) | |
{ | |
AssertAreEqual(format, innerImage.FileFormat); | |
// Let's invert the linked smart object image | |
InvertImage(innerImage); | |
innerImage.Save(linkOutputPath); | |
// Let's replace the linked smart object image in the PSD layer | |
smartObjectLayer.ReplaceContents(linkOutputPath); | |
} | |
// Let's check if the updated image is saved correctly | |
image.Save(psd2OutputPath, new PsdOptions(image)); | |
image.Save(png2OutputPath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); | |
} | |
} | |
// Inverts the image. | |
void InvertImage(RasterImage innerImage) | |
{ | |
var innerPsdImage = innerImage as PsdImage; | |
if (innerPsdImage != null) | |
{ | |
InvertRasterImage(innerPsdImage.Layers[0]); | |
} | |
else | |
{ | |
InvertRasterImage(innerImage); | |
} | |
} | |
// Inverts the raster image. | |
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); | |
} | |
// Gets the format extension. | |
string GetFormatExt(FileFormat format) | |
{ | |
string formatExt = format == FileFormat.Jpeg2000 ? "jpf" : format.ToString().ToLowerInvariant(); | |
return formatExt; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
{ | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_PSD(); | |
string sourceFileName = dataDir + "Rectangle.psd"; | |
string exportPath = dataDir + "Rectangle_changed.psd"; | |
var im = (PsdImage)Image.Load(sourceFileName); | |
using (im) | |
{ | |
var resource = GetVmskResource(im); | |
// Reading | |
if (resource.IsDisabled != false || | |
resource.IsInverted != false || | |
resource.IsNotLinked != false || | |
resource.Paths.Length != 7 || | |
resource.Paths[0].Type != VectorPathType.PathFillRuleRecord || | |
resource.Paths[1].Type != VectorPathType.InitialFillRuleRecord || | |
resource.Paths[2].Type != VectorPathType.ClosedSubpathLengthRecord || | |
resource.Paths[3].Type != VectorPathType.ClosedSubpathBezierKnotUnlinked || | |
resource.Paths[4].Type != VectorPathType.ClosedSubpathBezierKnotUnlinked || | |
resource.Paths[5].Type != VectorPathType.ClosedSubpathBezierKnotUnlinked || | |
resource.Paths[6].Type != VectorPathType.ClosedSubpathBezierKnotUnlinked) | |
{ | |
throw new Exception("VmskResource was read wrong"); | |
} | |
var pathFillRule = (PathFillRuleRecord)resource.Paths[0]; | |
var initialFillRule = (InitialFillRuleRecord)resource.Paths[1]; | |
var subpathLength = (LengthRecord)resource.Paths[2]; | |
// Path fill rule doesn't contain any additional information | |
if (pathFillRule.Type != VectorPathType.PathFillRuleRecord || | |
initialFillRule.Type != VectorPathType.InitialFillRuleRecord || | |
initialFillRule.IsFillStartsWithAllPixels != false || | |
subpathLength.Type != VectorPathType.ClosedSubpathLengthRecord || | |
subpathLength.IsClosed != true || | |
subpathLength.IsOpen != false) | |
{ | |
throw new Exception("VmskResource paths were read wrong"); | |
} | |
// Editing | |
resource.IsDisabled = true; | |
resource.IsInverted = true; | |
resource.IsNotLinked = true; | |
var bezierKnot = (BezierKnotRecord)resource.Paths[3]; | |
bezierKnot.Points[0] = new Point(0, 0); | |
bezierKnot = (BezierKnotRecord)resource.Paths[4]; | |
bezierKnot.Points[0] = new Point(8039797, 10905190); | |
initialFillRule.IsFillStartsWithAllPixels = true; | |
subpathLength.IsClosed = false; | |
im.Save(exportPath); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
{ | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_PSD(); | |
string sourceFileName = dataDir + "EmptyRectangle.psd"; | |
string exportPath = dataDir + "EmptyRectangle_changed.psd"; | |
var im = (PsdImage)Image.Load(sourceFileName); | |
using (im) | |
{ | |
var resource = GetVsmsResource(im); | |
// Reading | |
if (resource.IsDisabled != false || | |
resource.IsInverted != false || | |
resource.IsNotLinked != false || | |
resource.Paths.Length != 7 || | |
resource.Paths[0].Type != VectorPathType.PathFillRuleRecord || | |
resource.Paths[1].Type != VectorPathType.InitialFillRuleRecord || | |
resource.Paths[2].Type != VectorPathType.ClosedSubpathLengthRecord || | |
resource.Paths[3].Type != VectorPathType.ClosedSubpathBezierKnotUnlinked || | |
resource.Paths[4].Type != VectorPathType.ClosedSubpathBezierKnotUnlinked || | |
resource.Paths[5].Type != VectorPathType.ClosedSubpathBezierKnotUnlinked || | |
resource.Paths[6].Type != VectorPathType.ClosedSubpathBezierKnotUnlinked) | |
{ | |
throw new Exception("VsmsResource was read wrong"); | |
} | |
var pathFillRule = (PathFillRuleRecord)resource.Paths[0]; | |
var initialFillRule = (InitialFillRuleRecord)resource.Paths[1]; | |
var subpathLength = (LengthRecord)resource.Paths[2]; | |
// Path fill rule doesn't contain any additional information | |
if (pathFillRule.Type != VectorPathType.PathFillRuleRecord || | |
initialFillRule.Type != VectorPathType.InitialFillRuleRecord || | |
initialFillRule.IsFillStartsWithAllPixels != false || | |
subpathLength.Type != VectorPathType.ClosedSubpathLengthRecord || | |
subpathLength.IsClosed != true || | |
subpathLength.IsOpen != false) | |
{ | |
throw new Exception("VsmsResource paths were read wrong"); | |
} | |
// Editing | |
resource.IsDisabled = true; | |
resource.IsInverted = true; | |
resource.IsNotLinked = true; | |
var bezierKnot = (BezierKnotRecord)resource.Paths[3]; | |
bezierKnot.Points[0] = new Point(0, 0); | |
bezierKnot = (BezierKnotRecord)resource.Paths[4]; | |
bezierKnot.Points[0] = new Point(8039798, 10905191); | |
initialFillRule.IsFillStartsWithAllPixels = true; | |
subpathLength.IsClosed = false; | |
im.Save(exportPath); | |
} | |
} | |
static VsmsResource GetVsmsResource(PsdImage image) | |
{ | |
var layer = image.Layers[1]; | |
VsmsResource resource = null; | |
var resources = layer.Resources; | |
for (int i = 0; i < resources.Length; i++) | |
{ | |
if (resources[i] is VsmsResource) | |
{ | |
resource = (VsmsResource)resources[i]; | |
break; | |
} | |
} | |
if (resource == null) | |
{ | |
throw new Exception("VsmsResource not found"); | |
} | |
return resource; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
var sourceFile1 = dataDir + "FillOpacitySample.psd"; | |
var sourceFile2 = dataDir + "ThreeRegularLayersSemiTransparent.psd"; | |
var exportPath = dataDir + "MergedLayersFromTwoDifferentPsd.psd"; | |
using (var im1 = (PsdImage)(Image.Load(sourceFile1))) | |
{ | |
var layer1 = im1.Layers[1]; | |
using (var im2 = (PsdImage)(Image.Load(sourceFile2))) | |
{ | |
var layer2 = im2.Layers[0]; | |
layer1.MergeLayerTo(layer2); | |
im2.Save(exportPath); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
{ | |
// Load a PSD file as an image and cast it into PsdImage | |
using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "layers.psd")) | |
{ | |
PsdOptions saveOptions = new PsdOptions(); | |
saveOptions.CompressionMethod = CompressionMethod.Raw; | |
psdImage.Save(stream, saveOptions); | |
} | |
// Now reopen the newly created image. But first seek to the beginning of stream since after saving seek is at the end now. | |
stream.Seek(0, System.IO.SeekOrigin.Begin); | |
using (PsdImage psdImage = (PsdImage)Image.Load(stream)) | |
{ | |
Graphics graphics = new Graphics(psdImage); | |
// Perform graphics operations. | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Load a PSD file as an image and cast it into PsdImage | |
using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "layers.psd")) | |
{ | |
PsdOptions saveOptions = new PsdOptions(); | |
saveOptions.CompressionMethod = CompressionMethod.Raw; | |
psdImage.Save(dataDir + "uncompressed_out.psd", saveOptions); | |
} | |
// Now reopen the newly created image. | |
using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "uncompressed_out.psd")) | |
{ | |
Graphics graphics = new Graphics(psdImage); | |
// Perform graphics operations. | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Load a PSD file as an image and cast it into PsdImage | |
using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "layers.psd")) | |
{ | |
foreach (var layer in psdImage.Layers) | |
{ | |
if (layer is TextLayer) | |
{ | |
TextLayer textLayer = layer as TextLayer; | |
textLayer.UpdateText("test update", new Point(0, 0), 15.0f, Color.Purple); | |
} | |
} | |
psdImage.Save(dataDir + "UpdateTextLayerInPSDFile_out.psd"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
//The following example demonstrates how you can obtain the document conversion progress | |
string sourceFilePath = "Apple.psd"; | |
Stream outputStream = new MemoryStream(); | |
ProgressEventHandler localProgressEventHandler = delegate (ProgressEventHandlerInfo progressInfo) | |
{ | |
string message = string.Format( | |
"{0} {1}: {2} out of {3}", | |
progressInfo.Description, | |
progressInfo.EventType, | |
progressInfo.Value, | |
progressInfo.MaxValue); | |
Console.WriteLine(message); | |
}; | |
Console.WriteLine("---------- Loading Apple.psd ----------"); | |
var loadOptions = new PsdLoadOptions() { ProgressEventHandler = localProgressEventHandler }; | |
using (PsdImage image = (PsdImage)Image.Load(sourceFilePath, loadOptions)) | |
{ | |
Console.WriteLine("---------- Saving Apple.psd to PNG format ----------"); | |
image.Save( | |
outputStream, | |
new PngOptions() | |
{ | |
ColorType = PngColorType.Truecolor, | |
ProgressEventHandler = localProgressEventHandler | |
}); | |
Console.WriteLine("---------- Saving Apple.psd to PSD format ----------"); | |
image.Save( | |
outputStream, | |
new PsdOptions() | |
{ | |
ColorMode = ColorModes.Rgb, | |
ChannelsCount = 4, | |
ProgressEventHandler = localProgressEventHandler | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Load a PSD file as an image and cast it into PsdImage | |
using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "layers.psd")) | |
{ | |
// Create an instance of TiffOptions for the resultant image | |
TiffOptions outputSettings = new TiffOptions(TiffExpectedFormat.Default); | |
// Set BitsPerSample, Compression, Photometric mode and graycale palette | |
outputSettings.BitsPerSample = new ushort[] { 4 }; | |
outputSettings.Compression = TiffCompressions.Lzw; | |
outputSettings.Photometric = TiffPhotometrics.Palette; | |
outputSettings.Palette = ColorPaletteHelper.Create4BitGrayscale(true); | |
psdImage.Save(dataDir + "SampleTiff_out.tiff", outputSettings); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Load a PSD file as an image and cast it into PsdImage | |
using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "layers.psd")) | |
{ | |
// Initialize tiff frame list. | |
//List<TiffFrame> frames = new List<TiffFrame>(); | |
// Iterate over each layer of PsdImage and convert it to Tiff frame. | |
//foreach (var layer in psdImage.Layers) | |
//{ | |
// TiffFrame frame = new TiffFrame(layer, new TiffOptions(FileFormats.Tiff.Enums.TiffExpectedFormat.TiffLzwCmyk)); | |
// frames.Add(frame); | |
//} | |
// Create a new TiffImage with frames created earlier and save to disk. | |
//TiffImage tiffImage = new TiffImage(frames.ToArray()); | |
//tiffImage.Save(dataDir + "ExportToMultiPageTiff_output.tif"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Load a PSD file as an image and cast it into PsdImage | |
using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "layers.psd")) | |
{ | |
// Create an instance of TiffOptions while specifying desired format Passsing TiffExpectedFormat.TiffJpegRGB will set the compression to Jpeg and BitsPerPixel according to the RGB color space. | |
TiffOptions options = new TiffOptions(TiffExpectedFormat.TiffJpegRgb); | |
psdImage.Save(dataDir + "SampleTiff_out.tiff", options); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Create an instance of TiffOptions and set its various properties | |
TiffOptions options = new TiffOptions(TiffExpectedFormat.Default); | |
options.BitsPerSample = new ushort[] { 8, 8, 8 }; | |
options.Photometric = TiffPhotometrics.Rgb; | |
options.Xresolution = new TiffRational(72); | |
options.Yresolution = new TiffRational(72); | |
options.ResolutionUnit = TiffResolutionUnits.Inch; | |
options.PlanarConfiguration = TiffPlanarConfigs.Contiguous; | |
// Set the Compression to AdobeDeflate | |
options.Compression = TiffCompressions.AdobeDeflate; | |
//Create a new image with specific size and TiffOptions settings | |
using (PsdImage image = new PsdImage(100, 100)) | |
{ | |
// Fill image data. | |
int count = image.Width * image.Height; | |
int[] pixels = new int[count]; | |
for (int i = 0; i < count; i++) | |
{ | |
pixels[i] = Color.Red.ToArgb(); | |
} | |
// Save the newly created pixels. | |
image.SaveArgb32Pixels(image.Bounds, pixels); | |
// Save resultant image | |
image.Save(dataDir + "TIFFwithAdobeDeflateCompression_output.tif", options); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Load a PSD file as an image and cast it into PsdImage | |
using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "layers.psd")) | |
{ | |
// Create an instance of TiffOptions while specifying desired format and compression | |
TiffOptions options = new TiffOptions(TiffExpectedFormat.TiffDeflateRgb); | |
options.Compression = TiffCompressions.AdobeDeflate; | |
psdImage.Save(dataDir + "TIFFwithDeflateCompression_out.tiff", options); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string outputFilePath = dataDir + "PsdResult.psd"; | |
var filesList = new string[] | |
{ | |
"PsdExample.psd", | |
"BmpExample.bmp", | |
"GifExample.gif", | |
"Jpeg2000Example.jpf", | |
"JpegExample.jpg", | |
"PngExample.png", | |
"TiffExample.tif", | |
}; | |
using (var image = new PsdImage(200, 200)) | |
{ | |
foreach (var fileName in filesList) | |
{ | |
string filePath = dataDir + fileName; | |
using (var stream = new FileStream(filePath, FileMode.Open)) | |
{ | |
Layer layer = null; | |
try | |
{ | |
layer = new Layer(stream); | |
image.AddLayer(layer); | |
} | |
catch (Exception e) | |
{ | |
if (layer != null) | |
{ | |
layer.Dispose(); | |
} | |
throw e; | |
} | |
} | |
} | |
image.Save(outputFilePath); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Tests that the layer, imported from an image, is converted to smart object layer and the saved PSD file is correct. | |
// The path to the documents directory. | |
string SourceDir = RunExamples.GetDataDir_PSD(); | |
string OutputDir = RunExamples.GetDataDir_Output(); | |
string outputFilePath = OutputDir + "layerTest2.psd"; | |
string outputPngFilePath = Path.ChangeExtension(outputFilePath, ".png"); | |
using (PsdImage image = (PsdImage)Image.Load(SourceDir + "layerTest1.psd")) | |
{ | |
string layerFilePath = SourceDir + "picture.jpg"; | |
using (var stream = new FileStream(layerFilePath, FileMode.Open)) | |
{ | |
Layer layer = null; | |
try | |
{ | |
layer = new Layer(stream); | |
image.AddLayer(layer); | |
} | |
catch (Exception) | |
{ | |
if (layer != null) | |
{ | |
layer.Dispose(); | |
} | |
throw; | |
} | |
var layer2 = image.Layers[2]; | |
var layer3 = image.SmartObjectProvider.ConvertToSmartObject(image.Layers.Length - 1); | |
var bounds = layer3.Bounds; | |
layer3.Left = (image.Width - layer3.Width) / 2; | |
layer3.Top = layer2.Top; | |
layer3.Right = layer3.Left + bounds.Width; | |
layer3.Bottom = layer3.Top + bounds.Height; | |
image.Save(outputFilePath); | |
image.Save(outputPngFilePath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string dataDir = baseFolder; | |
string outputDir = output; | |
// These examples demonstrate how to copy smart object layers in a PSD image. | |
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; // The layer number to copy | |
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 + " shared image"; | |
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)) | |
{ | |
// Let's invert the embedded smart object image (for an inner PSD image we invert only its first layer) | |
InvertImage(innerImage); | |
// Let's replace the embedded smart object image in the PSD layer | |
smartObjectLayer.ReplaceContents(innerImage); | |
} | |
// The duplicated layer shares its imbedded image with the original smart object | |
// and it should be updated explicitly otherwise its rendering cache remains unchanged. | |
// We update every smart object to make sure that the new layer created by NewSmartObjectViaCopy | |
// does not share the embedded image with the others. | |
image.SmartObjectProvider.UpdateAllModifiedContent(); | |
image.Save(pngOutputPath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); | |
image.Save(psdOutputPath, new PsdOptions(image)); | |
} | |
} | |
// Inverts the raster image including the PSD image. | |
void InvertImage(RasterImage innerImage) | |
{ | |
var innerPsdImage = innerImage as PsdImage; | |
if (innerPsdImage != null) | |
{ | |
InvertRasterImage(innerPsdImage.Layers[0]); | |
} | |
else | |
{ | |
InvertRasterImage(innerImage); | |
} | |
} | |
// Inverts the raster image. | |
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")); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
void AssertAreEqual(object actual, object expected) | |
{ | |
if (!object.Equals(actual, expected)) | |
{ | |
throw new FormatException(string.Format("Actual value {0} are not equal to expected {1}.", actual, expected)); | |
} | |
} | |
// This example demonstrates how to change the smart object layer in the PSD file and export / update smart object original embedded contents. | |
const int left = 0; | |
const int top = 0; | |
const int right = 0xb; | |
const int bottom = 0x10; | |
FileFormat[] formats = new[] | |
{ | |
FileFormat.Png, FileFormat.Psd, FileFormat.Bmp, FileFormat.Jpeg, FileFormat.Gif, FileFormat.Tiff, FileFormat.Jpeg2000 | |
}; | |
foreach (FileFormat format in formats) | |
{ | |
string formatString = format.ToString().ToLowerInvariant(); | |
string formatExt = format == FileFormat.Jpeg2000 ? "jpf" : formatString; | |
string fileName = "r-embedded-" + formatString; | |
string sourceFilePath = baseFolder + fileName + ".psd"; | |
string pngOutputPath = output + fileName + "_output.png"; | |
string psdOutputPath = output + fileName + "_output.psd"; | |
string png2OutputPath = output + fileName + "_updated.png"; | |
string psd2OutputPath = output + fileName + "_updated.psd"; | |
string exportPath = output + fileName + "_export." + formatExt; | |
using (PsdImage image = (PsdImage)Image.Load(sourceFilePath)) | |
{ | |
var smartObjectLayer = (SmartObjectLayer)image.Layers[0]; | |
AssertAreEqual(left, smartObjectLayer.ContentsBounds.Left); | |
AssertAreEqual(top, smartObjectLayer.ContentsBounds.Top); | |
AssertAreEqual(right, smartObjectLayer.ContentsBounds.Right); | |
AssertAreEqual(bottom, smartObjectLayer.ContentsBounds.Bottom); | |
// Let's export the embedded smart object image from the PSD smart object layer | |
smartObjectLayer.ExportContents(exportPath); | |
// Let's check if the original image is saved correctly | |
image.Save(psdOutputPath, new PsdOptions(image)); | |
image.Save(pngOutputPath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); | |
using (var innerImage = (RasterImage)smartObjectLayer.LoadContents(null)) | |
{ | |
AssertAreEqual(format, innerImage.FileFormat); | |
// Let's invert original smart object image | |
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); | |
// Let's replace the embedded smart object image in the PSD layer | |
smartObjectLayer.ReplaceContents(innerImage); | |
} | |
// Let's check if the updated image is saved correctly | |
image.Save(psd2OutputPath, new PsdOptions(image)); | |
image.Save(png2OutputPath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// This example demonstrates that the ReplaceContents method works correctly when the new content file has a different resolution. | |
// The path to the documents directory. | |
string SourceDir = RunExamples.GetDataDir_PSD(); | |
string OutputDir = RunExamples.GetDataDir_Output(); | |
string fileName = "CommonPsb.psd"; | |
string filePath = SourceDir + fileName; // original PSD image | |
string newContentPath = SourceDir + "image.jpg"; // the new content file for the smart object | |
string outputFilePath = OutputDir + "ChangedPsd"; | |
string pngOutputPath = outputFilePath + ".png"; // the output PNG file | |
string psdOutputPath = outputFilePath + ".psd"; // the output PSD file | |
using (PsdImage psd = (PsdImage)Image.Load(filePath)) | |
{ | |
for (int i = 0; i < psd.Layers.Length; i++) | |
{ | |
var layer = psd.Layers[i]; | |
SmartObjectLayer smartObjectLayer = layer as SmartObjectLayer; | |
if (smartObjectLayer != null) | |
{ | |
smartObjectLayer.ReplaceContents(newContentPath); | |
psd.Save(psdOutputPath); | |
psd.Save(pngOutputPath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFilePath = baseDir + "apple.psd"; | |
string outputFilePath = outputDir + "apple_with_hidden_gorup_output.psd"; | |
// make changes in layer names and save it | |
using (var image = (PsdImage)Image.Load(sourceFilePath)) | |
{ | |
for (int i = 0; i < image.Layers.Length; i++) | |
{ | |
var layer = image.Layers[i]; | |
// Turn off everything inside a group | |
if (layer is LayerGroup) | |
{ | |
layer.IsVisible = false; | |
} | |
} | |
image.Save(outputFilePath); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
{ | |
// folder with background | |
LayerGroup bg_folder = (LayerGroup)psdImage.Layers[0]; | |
// folder with content | |
LayerGroup content_folder = (LayerGroup)psdImage.Layers[4]; | |
bg_folder.Save(OutputDir + "background.png", new PngOptions()); | |
content_folder.Save(OutputDir + "content.png", new PngOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string sourceFileName = baseDir + "Apple.psd"; | |
string outputFileName = outputDir + "OutputApple"; | |
using (PsdImage image = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
if (image.Layers.Length < 23) | |
{ | |
throw new Exception("There is not 23rd layer."); | |
} | |
var layer = image.Layers[23] as LayerGroup; | |
if (layer == null) | |
{ | |
throw new Exception("The 23rd layer is not a layer group."); | |
} | |
if (layer.Name != "AdjustmentGroup") | |
{ | |
throw new Exception("The 23rd layer name is not 'AdjustmentGroup'."); | |
} | |
if (layer.BlendModeKey != BlendMode.PassThrough) | |
{ | |
throw new Exception("AdjustmentGroup layer should have 'pass through' blend mode."); | |
} | |
image.Save(outputFileName + ".psd", new PsdOptions(image)); | |
image.Save(outputFileName + ".png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); | |
layer.BlendModeKey = BlendMode.Normal; | |
image.Save(outputFileName + "Normal.psd", new PsdOptions(image)); | |
image.Save(outputFileName + "Normal.png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
private static void PathManipulationExample(string fileName = "PathExample.psd", string output = "output_PathExample.psd") | |
{ | |
using (var psdImage = (PsdImage)Image.Load(fileName)) | |
{ | |
// Now we can use VectorPath instance and manipulate path data. | |
VectorPath vectorPath = VectorDataProvider.CreateVectorPathForLayer(psdImage.Layers[1]); | |
// Change the fill color of vector path | |
vectorPath.FillColor = Color.Violet; | |
// removing the first point, changing IsClosed state of the shape and move one point upper. | |
PathShape heartShape = vectorPath.Shapes[0]; | |
heartShape.Points.RemoveAt(0); | |
heartShape.IsClosed = false; | |
heartShape.Points[2].Shift(0, 25); | |
// add new shape | |
PathShape newShape = new PathShape(); | |
newShape.Points.Add(new BezierKnot(new PointF(65, 175), true)); | |
newShape.Points.Add(new BezierKnot(new PointF(65, 210), true)); | |
newShape.Points.Add(new BezierKnot(new PointF(190, 210), true)); | |
newShape.Points.Add(new BezierKnot(new PointF(190, 175), true)); | |
vectorPath.Shapes.Add(newShape); | |
// update path data in layer | |
VectorDataProvider.UpdateLayerFromVectorPath(psdImage.Layers[1], vectorPath); | |
psdImage.Save(output); | |
} | |
} | |
#region Vector path editor (Here placed classes for edit vector paths). | |
/// <summary> | |
/// The class that provides work between <see cref="Layer"/> and <see cref="VectorPath"/>. | |
/// </summary> | |
public static class VectorDataProvider | |
{ | |
/// <summary> | |
/// Creates the <see cref="VectorPath"/> instance based on resources from input layer. | |
/// </summary> | |
/// <param name="psdLayer">The psd layer.</param> | |
/// <returns>the <see cref="VectorPath"/> instance based on resources from input layer.</returns> | |
public static VectorPath CreateVectorPathForLayer(Layer psdLayer) | |
{ | |
VectorPathDataResource pathResource = FindVectorPathDataResource(psdLayer); | |
SoCoResource soCoResource = FindSoCoResource(psdLayer); | |
VectorPath vectorPath = new VectorPath(pathResource); | |
if (soCoResource != null) | |
{ | |
vectorPath.FillColor = soCoResource.Color; | |
} | |
return vectorPath; | |
} | |
/// <summary> | |
/// Updates the input layer resources from <see cref="VectorPath"/> instance, or replace by new path resource and updates. | |
/// </summary> | |
/// <param name="psdLayer">The psd layer.</param> | |
/// <param name="vectorPath">The vector path.</param> | |
/// <param name="pathResource">The new path resource.</param> | |
public static void UpdateLayerFromVectorPath(Layer psdLayer, VectorPath vectorPath, VectorPathDataResource pathResource = null) | |
{ | |
if (pathResource == null) | |
{ | |
pathResource = FindVectorPathDataResource(psdLayer); | |
} | |
VogkResource vogkResource = FindVogkResource(psdLayer); | |
SoCoResource soCoResource = FindSoCoResource(psdLayer); | |
if (soCoResource == null) | |
{ | |
soCoResource = new SoCoResource(); | |
} | |
UpdateResources(pathResource, vogkResource, soCoResource, vectorPath); | |
ReplaceVectorPathDataResourceInLayer(psdLayer, pathResource, vogkResource, soCoResource); | |
} | |
/// <summary> | |
/// Updates resources data from <see cref="VectorPath"/> instance. | |
/// </summary> | |
/// <param name="pathResource">The path resource.</param> | |
/// <param name="vogkResource">The vector origination data resource.</param> | |
/// <param name="soCoResource">The solid color resource.</param> | |
/// <param name="vectorPath">The vector path.</param> | |
private static void UpdateResources(VectorPathDataResource pathResource, VogkResource vogkResource, SoCoResource soCoResource, VectorPath vectorPath) | |
{ | |
pathResource.Version = vectorPath.Version; | |
pathResource.IsNotLinked = vectorPath.IsNotLinked; | |
pathResource.IsDisabled = vectorPath.IsDisabled; | |
pathResource.IsInverted = vectorPath.IsInverted; | |
List<VectorShapeOriginSettings> originSettings = new List<VectorShapeOriginSettings>(); | |
List<VectorPathRecord> path = new List<VectorPathRecord>(); | |
path.Add(new PathFillRuleRecord(null)); | |
path.Add(new InitialFillRuleRecord(vectorPath.IsFillStartsWithAllPixels)); | |
for (ushort i = 0; i < vectorPath.Shapes.Count; i++) | |
{ | |
PathShape shape = vectorPath.Shapes[i]; | |
shape.ShapeIndex = i; | |
path.AddRange(shape.ToVectorPathRecords()); | |
originSettings.Add(new VectorShapeOriginSettings(true, i)); | |
} | |
pathResource.Paths = path.ToArray(); | |
vogkResource.ShapeOriginSettings = originSettings.ToArray(); | |
soCoResource.Color = vectorPath.FillColor; | |
} | |
/// <summary> | |
/// Replaces resources in layer by updated or new ones. | |
/// </summary> | |
/// <param name="psdLayer">The psd layer.</param> | |
/// <param name="pathResource">The path resource.</param> | |
/// <param name="vogkResource">The vector origination data resource.</param> | |
/// <param name="soCoResource">The solid color resource.</param> | |
private static void ReplaceVectorPathDataResourceInLayer(Layer psdLayer, VectorPathDataResource pathResource, VogkResource vogkResource, SoCoResource soCoResource) | |
{ | |
bool soCoResourceExist = false; | |
List<LayerResource> resources = new List<LayerResource>(psdLayer.Resources); | |
for (int i = 0; i < resources.Count; i++) | |
{ | |
LayerResource resource = resources[i]; | |
if (resource is VectorPathDataResource) | |
{ | |
resources[i] = pathResource; | |
} | |
else if (resource is VogkResource) | |
{ | |
resources[i] = vogkResource; | |
} | |
else if (resource is SoCoResource) | |
{ | |
resources[i] = soCoResource; | |
soCoResourceExist = true; | |
} | |
} | |
if (!soCoResourceExist) | |
{ | |
resources.Add(soCoResource); | |
} | |
psdLayer.Resources = resources.ToArray(); | |
} | |
/// <summary> | |
/// Finds the <see cref="VectorPathDataResource"/> resource in input layer resources. | |
/// </summary> | |
/// <param name="psdLayer">The psd layer.</param> | |
/// <returns>The <see cref="VectorPathDataResource"/> resource.</returns> | |
private static VectorPathDataResource FindVectorPathDataResource(Layer psdLayer) | |
{ | |
VectorPathDataResource pathResource = null; | |
foreach (var resource in psdLayer.Resources) | |
{ | |
if (resource is VectorPathDataResource) | |
{ | |
pathResource = (VectorPathDataResource)resource; | |
break; | |
} | |
} | |
return pathResource; | |
} | |
/// <summary> | |
/// Finds the <see cref="VogkResource"/> resource in input layer resources. | |
/// </summary> | |
/// <param name="psdLayer">The psd layer.</param> | |
/// <returns>The <see cref="VogkResource"/> resource.</returns> | |
private static VogkResource FindVogkResource(Layer psdLayer) | |
{ | |
VogkResource vogkResource = null; | |
foreach (var resource in psdLayer.Resources) | |
{ | |
if (resource is VogkResource) | |
{ | |
vogkResource = (VogkResource)resource; | |
break; | |
} | |
} | |
return vogkResource; | |
} | |
/// <summary> | |
/// Finds the <see cref="SoCoResource"/> resource in input layer resources. | |
/// </summary> | |
/// <param name="psdLayer">The psd layer.</param> | |
/// <returns>The <see cref="SoCoResource"/> resource.</returns> | |
private static SoCoResource FindSoCoResource(Layer psdLayer) | |
{ | |
SoCoResource soCoResource = null; | |
foreach (var resource in psdLayer.Resources) | |
{ | |
if (resource is SoCoResource) | |
{ | |
soCoResource = (SoCoResource)resource; | |
break; | |
} | |
} | |
return soCoResource; | |
} | |
} | |
/// <summary> | |
/// The Bezier curve knot, it contains one anchor point and two control points. | |
/// </summary> | |
public class BezierKnot | |
{ | |
/// <summary> | |
/// Initializes a new instance of the <see cref="BezierKnot" /> class. | |
/// </summary> | |
/// <param name="anchorPoint">The anchor point.</param> | |
/// <param name="controlPoint1">The first control point.</param> | |
/// <param name="controlPoint2">THe second control point.</param> | |
/// <param name="isLinked">The value indicating whether this knot is linked.</param> | |
public BezierKnot(PointF anchorPoint, PointF controlPoint1, PointF controlPoint2, bool isLinked) | |
{ | |
this.AnchorPoint = anchorPoint; | |
this.ControlPoint1 = controlPoint1; | |
this.ControlPoint2 = controlPoint2; | |
this.IsLinked = isLinked; | |
} | |
/// <summary> | |
/// Initializes a new instance of the <see cref="BezierKnot" /> class based on <see cref="BezierKnotRecord"/>. | |
/// </summary> | |
/// <param name="bezierKnotRecord">The <see cref="BezierKnotRecord"/>.</param> | |
public BezierKnot(BezierKnotRecord bezierKnotRecord) | |
{ | |
this.IsLinked = bezierKnotRecord.IsLinked; | |
this.ControlPoint1 = ResourcePointToPointF(bezierKnotRecord.Points[0]); | |
this.AnchorPoint = ResourcePointToPointF(bezierKnotRecord.Points[1]); | |
this.ControlPoint2 = ResourcePointToPointF(bezierKnotRecord.Points[2]); | |
} | |
/// <summary> | |
/// Initializes a new instance of the <see cref="BezierKnot" /> class. | |
/// </summary> | |
/// <param name="anchorPoint">The point to be anchor and control points.</param> | |
/// <param name="isLinked">The value indicating whether this knot is linked.</param> | |
public BezierKnot(PointF anchorPoint, bool isLinked) | |
: this(anchorPoint, anchorPoint, anchorPoint, isLinked) | |
{ | |
} | |
/// <summary> | |
/// Gets or sets a value indicating whether this instance is linked. | |
/// </summary> | |
public bool IsLinked { get; set; } | |
/// <summary> | |
/// Gets or sets the first control point. | |
/// </summary> | |
public PointF ControlPoint1 { get; set; } | |
/// <summary> | |
/// Gets or sets the anchor point. | |
/// </summary> | |
public PointF AnchorPoint { get; set; } | |
/// <summary> | |
/// Gets or sets the second control point. | |
/// </summary> | |
public PointF ControlPoint2 { get; set; } | |
/// <summary> | |
/// Creates the instance of <see cref="BezierKnotRecord"/> based on this instance. | |
/// </summary> | |
/// <param name="isClosed">Indicating whether this knot is in closed shape.</param> | |
/// <returns>The instance of <see cref="BezierKnotRecord"/> based on this instance.</returns> | |
public BezierKnotRecord ToBezierKnotRecord(bool isClosed) | |
{ | |
BezierKnotRecord record = new BezierKnotRecord(); | |
record.Points = new Point[] | |
{ | |
PointFToResourcePoint(this.ControlPoint1), | |
PointFToResourcePoint(this.AnchorPoint), | |
PointFToResourcePoint(this.ControlPoint2), | |
}; | |
record.IsLinked = this.IsLinked; | |
record.IsClosed = isClosed; | |
return record; | |
} | |
/// <summary> | |
/// Shifts this knot points by input values. | |
/// </summary> | |
/// <param name="xOffset">The x offset.</param> | |
/// <param name="yOffset">The y offset.</param> | |
public void Shift(float xOffset, float yOffset) | |
{ | |
this.ControlPoint1 = new PointF(this.ControlPoint1.X + xOffset, this.ControlPoint1.Y + yOffset); | |
this.AnchorPoint = new PointF(this.AnchorPoint.X + xOffset, this.AnchorPoint.Y + yOffset); | |
this.ControlPoint2 = new PointF(this.ControlPoint2.X + xOffset, this.ControlPoint2.Y + yOffset); | |
} | |
/// <summary> | |
/// Converts point values from resource to normal. | |
/// </summary> | |
/// <param name="point">The point with values from resource.</param> | |
/// <returns>The converted to normal point.</returns> | |
private static PointF ResourcePointToPointF(Point point) | |
{ | |
return new PointF(point.Y / 65535, point.X / 65535); | |
} | |
/// <summary> | |
/// Converts normal point values to resource point. | |
/// </summary> | |
/// <param name="point">The point.</param> | |
/// <returns>The point with values for resource.</returns> | |
private static Point PointFToResourcePoint(PointF point) | |
{ | |
return new Point((int)Math.Round(point.Y * 65535), (int)Math.Round(point.X * 65535)); | |
} | |
} | |
/// <summary> | |
/// The figure from the knots of the Bezier curve. | |
/// </summary> | |
public class PathShape | |
{ | |
/// <summary> | |
/// Initializes a new instance of the <see cref="PathShape" /> class. | |
/// </summary> | |
public PathShape() | |
{ | |
this.Points = new List<BezierKnot>(); | |
this.PathOperations = PathOperations.CombineShapes; | |
} | |
/// <summary> | |
/// Initializes a new instance of the <see cref="PathShape" /> class based on <see cref="VectorPathRecord"/>'s. | |
/// </summary> | |
/// <param name="lengthRecord">The length record.</param> | |
/// <param name="bezierKnotRecords">The bezier knot records.</param> | |
public PathShape(LengthRecord lengthRecord, List<BezierKnotRecord> bezierKnotRecords) | |
: this() | |
{ | |
this.IsClosed = lengthRecord.IsClosed; | |
this.PathOperations = lengthRecord.PathOperations; | |
this.ShapeIndex = lengthRecord.ShapeIndex; | |
this.InitFromResources(bezierKnotRecords); | |
} | |
/// <summary> | |
/// Gets or sets a value indicating whether this instance is closed. | |
/// </summary> | |
/// <value> | |
/// <c>true</c> if this instance is closed; otherwise, <c>false</c>. | |
/// </value> | |
public bool IsClosed { get; set; } | |
/// <summary> | |
/// Gets or sets the path operations (Boolean operations). | |
/// </summary> | |
public PathOperations PathOperations { get; set; } | |
/// <summary> | |
/// Gets or sets the index of current path shape in layer. | |
/// </summary> | |
public ushort ShapeIndex { get; set; } | |
/// <summary> | |
/// Gets the points of the Bezier curve. | |
/// </summary> | |
public List<BezierKnot> Points { get; private set; } | |
/// <summary> | |
/// Creates the <see cref="VectorPathRecord"/> records based on this instance. | |
/// </summary> | |
/// <returns>Returns one <see cref="LengthRecord"/> and <see cref="BezierKnotRecord"/> for each point in this instance.</returns> | |
public IEnumerable<VectorPathRecord> ToVectorPathRecords() | |
{ | |
List<VectorPathRecord> shapeRecords = new List<VectorPathRecord>(); | |
LengthRecord lengthRecord = new LengthRecord(); | |
lengthRecord.IsClosed = this.IsClosed; | |
lengthRecord.BezierKnotRecordsCount = this.Points.Count; | |
lengthRecord.PathOperations = this.PathOperations; | |
lengthRecord.ShapeIndex = this.ShapeIndex; | |
shapeRecords.Add(lengthRecord); | |
foreach (var bezierKnot in this.Points) | |
{ | |
shapeRecords.Add(bezierKnot.ToBezierKnotRecord(this.IsClosed)); | |
} | |
return shapeRecords; | |
} | |
/// <summary> | |
/// Initializes a values based on input records. | |
/// </summary> | |
/// <param name="bezierKnotRecords">The bezier knot records.</param> | |
private void InitFromResources(IEnumerable<BezierKnotRecord> bezierKnotRecords) | |
{ | |
List<BezierKnot> newPoints = new List<BezierKnot>(); | |
foreach (var record in bezierKnotRecords) | |
{ | |
newPoints.Add(new BezierKnot(record)); | |
} | |
this.Points = newPoints; | |
} | |
} | |
/// <summary> | |
/// The class that contains vector paths. | |
/// </summary> | |
public class VectorPath | |
{ | |
/// <summary> | |
/// Initializes a new instance of the <see cref="VectorPath" /> class based on <see cref="VectorPathDataResource"/>. | |
/// </summary> | |
/// <param name="vectorPathDataResource">The vector path data resource.</param> | |
public VectorPath(VectorPathDataResource vectorPathDataResource) | |
{ | |
this.InitFromResource(vectorPathDataResource); | |
} | |
/// <summary> | |
/// Gets or sets a value indicating whether is fill starts with all pixels. | |
/// </summary> | |
/// <value> | |
/// The is fill starts with all pixels. | |
/// </value> | |
public bool IsFillStartsWithAllPixels { get; set; } | |
/// <summary> | |
/// Gets the vector shapes. | |
/// </summary> | |
public List<PathShape> Shapes { get; private set; } | |
/// <summary> | |
/// The vector path fill color. | |
/// </summary> | |
public Color FillColor { get; set; } | |
/// <summary> | |
/// Gets or sets the version. | |
/// </summary> | |
/// <value> | |
/// The version. | |
/// </value> | |
public int Version { get; set; } | |
/// <summary> | |
/// Gets or sets a value indicating whether this instance is disabled. | |
/// </summary> | |
/// <value> | |
/// <c>true</c> if this instance is disabled; otherwise, <c>false</c>. | |
/// </value> | |
public bool IsDisabled { get; set; } | |
/// <summary> | |
/// Gets or sets a value indicating whether this instance is not linked. | |
/// </summary> | |
/// <value> | |
/// <c>true</c> if this instance is not linked; otherwise, <c>false</c>. | |
/// </value> | |
public bool IsNotLinked { get; set; } | |
/// <summary> | |
/// Gets or sets a value indicating whether this instance is inverted. | |
/// </summary> | |
/// <value> | |
/// <c>true</c> if this instance is inverted; otherwise, <c>false</c>. | |
/// </value> | |
public bool IsInverted { get; set; } | |
/// <summary> | |
/// Initializes a values based on input <see cref="VectorPathDataResource"/> resource. | |
/// </summary> | |
/// <param name="resource">The vector path data resource.</param> | |
private void InitFromResource(VectorPathDataResource resource) | |
{ | |
List<PathShape> newShapes = new List<PathShape>(); | |
InitialFillRuleRecord initialFillRuleRecord = null; | |
LengthRecord lengthRecord = null; | |
List<BezierKnotRecord> bezierKnotRecords = new List<BezierKnotRecord>(); | |
foreach (var pathRecord in resource.Paths) | |
{ | |
if (pathRecord is LengthRecord) | |
{ | |
if (bezierKnotRecords.Count > 0) | |
{ | |
newShapes.Add(new PathShape(lengthRecord, bezierKnotRecords)); | |
lengthRecord = null; | |
bezierKnotRecords.Clear(); | |
} | |
lengthRecord = (LengthRecord)pathRecord; | |
} | |
else if (pathRecord is BezierKnotRecord) | |
{ | |
bezierKnotRecords.Add((BezierKnotRecord)pathRecord); | |
} | |
else if (pathRecord is InitialFillRuleRecord) | |
{ | |
initialFillRuleRecord = (InitialFillRuleRecord)pathRecord; | |
} | |
} | |
if (bezierKnotRecords.Count > 0) | |
{ | |
newShapes.Add(new PathShape(lengthRecord, bezierKnotRecords)); | |
lengthRecord = null; | |
bezierKnotRecords.Clear(); | |
} | |
this.IsFillStartsWithAllPixels = initialFillRuleRecord != null ? initialFillRuleRecord.IsFillStartsWithAllPixels : false; | |
this.Shapes = newShapes; | |
this.Version = resource.Version; | |
this.IsNotLinked = resource.IsNotLinked; | |
this.IsDisabled = resource.IsDisabled; | |
this.IsInverted = resource.IsInverted; | |
} | |
} | |
#endregion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Create load options with important settings | |
var loadOpt = new PsdLoadOptions() { LoadEffectsResource = true }; | |
// Open PSD File and just work with animation TimeLine | |
using (PsdImage psdImage = (PsdImage)Image.Load(sourceFile, loadOpt)) | |
{ | |
Timeline timeline = psdImage.Timeline; | |
// Change delay of frame 2 | |
timeline.Frames[1].Delay = 15; | |
// Change opacity of 'Layer 1' on frame 2 | |
LayerState layerState11 = timeline.Frames[1].LayerStates[1]; | |
layerState11.Opacity = 50; | |
// move 'Layer 1' to left-bottom corner on frame 3 | |
LayerState layerState21 = timeline.Frames[2].LayerStates[1]; | |
layerState21.PositionOffset = new Point(-50, 230); | |
// Adds new frame | |
List<Frame> frames = new List<Frame>(timeline.Frames); | |
frames.Add(new Frame()); | |
timeline.Frames = frames.ToArray(); | |
// Change blendMode of 'Layer 1' on frame 4 | |
LayerState layerState31 = timeline.Frames[3].LayerStates[1]; | |
layerState31.BlendMode = BlendMode.Dissolve; | |
// Easy export to gif | |
timeline.Save(outputGif, new GifOptions()); | |
// Apply changes back to PsdImage instance | |
psdImage.Save(outputPsd); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Create load options with important settings | |
var loadOpt = new PsdLoadOptions() { LoadEffectsResource = true }; | |
// Open PSD File and just convert it to any other formats | |
using (PsdImage image = (PsdImage)Image.Load(sourceFileName, loadOpt)) | |
{ | |
image.Save(sourceFileName + ".pdf", new PdfOptions()); | |
image.Save(sourceFileName + ".jpg", new JpegOptions() { Quality = 75 }); | |
image.Save(sourceFileName + ".png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); | |
image.Save(sourceFileName + ".tif", new TiffOptions(TiffExpectedFormat.TiffNoCompressionRgba)); | |
image.Save(sourceFileName + ".gif", new GifOptions()); | |
image.Save(sourceFileName + ".bmp", new BmpOptions()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Create load options with important settings | |
var loadOpt = new PsdLoadOptions() { LoadEffectsResource = true }; | |
// Open PSD File and just work with different layers | |
using (PsdImage image = (PsdImage)Image.Load(sourceFileName, loadOpt)) | |
{ | |
var layers = image.Layers; | |
// Editing of Text Layers | |
var text = (TextLayer)layers[0]; | |
text.UpdateText("Easy to update text"); | |
// Editing of SmartObject | |
var smart = (SmartObjectLayer)layers[1]; | |
smart.ReplaceContents(Image.Load("ExternalImage.Psd")); | |
// Editing of Fill Layers | |
var fill = (FillLayer)layers[2]; | |
var fillSettings = (GradientFillSettings)fill.FillSettings; | |
fillSettings.ColorPoints = new IGradientColorPoint[] { new GradientColorPoint() { Color = Color.Red }, new GradientColorPoint() { Color = Color.Green } } | |
// Editing of different types of Adjustment Layers | |
var adj1 = (ColorBalanceAdjustmentLayer)layers[3]; | |
adj1.ShadowsYellowBlueBalance = 42; | |
var adj2 = (CurvesLayer)layers[4]; | |
var curveManager = (CurvesContinuousManager)adj2.GetCurvesManager(); | |
curveManager.AddCurvePoint(0, 50, 32); | |
// Editing of ShapeLayer | |
var shape = (ShapeLayer)layers[5]; | |
shape.Fill = fillSettings; | |
var pathShape = new PathShape(); | |
pathShape.SetItems( | |
new BezierKnotRecord[] { | |
new BezierKnotRecord() { | |
Points = new Point[] { | |
new Point(5, 5), | |
new Point(25, 45), | |
new Point(32, 42) } } } | |
); | |
shape.Path.SetItems(new PathShape[] { pathShape } ); | |
image.Save("EditedOutput.psd"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Create load options with important settings | |
var loadOpt = new PsdLoadOptions() { LoadEffectsResource = true }; | |
// Open PSD File and just work with different layers | |
using (PsdImage image = (PsdImage)Image.Load(sourceFileName, loadOpt)) | |
{ | |
var brightnessContrast = image.AddBrightnessContrastAdjustmentLayer(32, 50); | |
// Using Curves Adjustment Layer | |
var curves = image.AddCurvesAdjustmentLayer(); | |
// Using levels Adjustment Layer | |
var levels = image.AddLevelsAdjustmentLayer(); | |
levels.MasterChannel.InputShadowLevel = 12; | |
// Using Photo Filter Adjustment Layer | |
var photoFilter = image.AddPhotoFilterLayer(Color.Yellow); | |
photoFilter.Density = 16; | |
// Using Exposure Adjustment Layer | |
var exposure = image.AddExposureAdjustmentLayer(); | |
exposure.Exposure = 9; | |
// Using Vibrance Adjustment Layer | |
var vibrance = image.AddVibranceAdjustmentLayer(); | |
vibrance.Saturation = -7; | |
vibrance.Vibrance = 11; | |
// Using Hue/Saturation Adjustment Layer | |
var hueSaturation = image.AddHueSaturationAdjustmentLayer(); | |
hueSaturation.Saturation = 4; | |
hueSaturation.Hue = -43; | |
// Using Channel Mixer Adjustment Layer | |
var channelMixer = image.AddChannelMixerAdjustmentLayer(); | |
var channel = (RgbMixerChannel)channelMixer.GetChannelByIndex(1); | |
channel.Blue = 10; | |
channel.Green = -10; | |
// Using Selective Adjustment Layer | |
var selectiveColor = image.AddSelectiveColorAdjustmentLayer(); | |
var correction = selectiveColor.GetCmykCorrection(SelectiveColorsTypes.Blues); | |
correction.Yellow = 19; | |
// Using Posterize Adjustment Layer | |
var posterize = image.AddPosterizeAdjustmentLayer(); | |
posterize.Levels = 12; | |
// Using Black&White Adjustment Layer | |
var blackWhite = image.AddBlackWhiteAdjustmentLayer(); | |
// Using Thresold Adjustment Layer | |
var thresold = image.AddThresholdAdjustmentLayer(); | |
thresold.Level = 16; | |
image.Save("AdjustedPhoto.psd"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment