Last active
June 7, 2024 08:59
-
-
Save aspose-com-gists/8a4c9d34ce856d1642fc7c0ce974175c to your computer and use it in GitHub Desktop.
Aspose.PSD for .NET
This gist exceeds the recommended number of files (~10).
To access all files, please clone this gist.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 = "GradientOverlay.psd"; | |
string exportPath = "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(exportPath, 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.0); | |
AssertIsTrue(transparencyPoint.Location == 0); | |
transparencyPoint = fillSettings.TransparencyPoints[1]; | |
AssertIsTrue(transparencyPoint.MedianPointLocation == 50); | |
AssertIsTrue(transparencyPoint.Opacity == 100.0); | |
AssertIsTrue(transparencyPoint.Location == 2315); | |
transparencyPoint = fillSettings.TransparencyPoints[2]; | |
AssertIsTrue(transparencyPoint.MedianPointLocation == 25); | |
AssertIsTrue(transparencyPoint.Opacity == 25.0); | |
AssertIsTrue(transparencyPoint.Location == 4096); | |
} | |
catch (Exception e) | |
{ | |
string ex = e.StackTrace; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled 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 = "gradient_map_src.psd"; | |
string outputFile = "gradient_map_src_output.psd"; | |
using (PsdImage im = (PsdImage)Image.Load(sourceFile)) | |
{ | |
// Add Gradient map adjustment layer. | |
GradientMapLayer layer = im.AddGradientMapAdjustmentLayer(); | |
layer.GradientSettings.Reverse = true; | |
im.Save(outputFile); | |
} | |
// Check saved changes | |
using (PsdImage im = (PsdImage)Image.Load(outputFile)) | |
{ | |
GradientMapLayer gradientMapLayer = im.Layers[1] as GradientMapLayer; | |
GradientFillSettings gradientSettings = (GradientFillSettings)gradientMapLayer.GradientSettings; | |
AssertAreEqual(0.0, gradientSettings.Angle); | |
AssertAreEqual((short)4096, gradientSettings.Interpolation); | |
AssertAreEqual(true, gradientSettings.Reverse); | |
AssertAreEqual(false, gradientSettings.AlignWithLayer); | |
AssertAreEqual(false, gradientSettings.Dither); | |
AssertAreEqual(GradientType.Linear, gradientSettings.GradientType); | |
AssertAreEqual(100, gradientSettings.Scale); | |
AssertAreEqual(0.0, gradientSettings.HorizontalOffset); | |
AssertAreEqual(0.0, gradientSettings.VerticalOffset); | |
AssertAreEqual("Custom", gradientSettings.GradientName); | |
} | |
void AssertAreEqual(object expected, object actual, string message = null) | |
{ | |
if (!object.Equals(expected, actual)) | |
{ | |
throw new Exception(message ?? "Objects are not equal."); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 = "PatternOverlay.psd"; | |
string exportPath = "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".ToUpperInvariant()) || | |
(settings.PatternName != "$$$/Presets/Patterns/OpticalSquares=Optical Squares") || | |
(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; | |
settings.PatternName = newPatternName; | |
settings.PatternId = guid.ToString(); | |
settings.PatternData = newPattern; | |
settings.PatternWidth = newPatternBounds.Width; | |
settings.PatternHeight = newPatternBounds.Height; | |
im.Save(exportPath); | |
} | |
// Test file after edit | |
using (var im = (PsdImage)Image.Load(exportPath, 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; | |
break; | |
} | |
} | |
if (resource == null) | |
{ | |
throw new Exception("PattResource not found"); | |
} | |
// Check the pattern data | |
var patternData = resource.Patterns[1]; | |
if ((newPatternBounds != new Rectangle(0, 0, patternData.Width, patternData.Height)) || | |
(patternData.PatternId != guid.ToString().ToUpperInvariant()) || | |
((patternData.Name + "\0") != newPatternName) | |
) | |
{ | |
throw new Exception("Pattern was set wrong"); | |
} | |
} | |
catch (Exception e) | |
{ | |
string ex = e.StackTrace; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled 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 outputFile = "AddShapeLayer_output.psd"; | |
const int ImgToPsdRatio = 256 * 65535; | |
using (PsdImage newPsd = new PsdImage(600, 400)) | |
{ | |
ShapeLayer layer = newPsd.AddShapeLayer(); | |
var newShape = GenerateNewShape(newPsd.Size); | |
List<IPathShape> newShapes = new List<IPathShape>(); | |
newShapes.Add(newShape); | |
layer.Path.SetItems(newShapes.ToArray()); | |
layer.Update(); | |
newPsd.Save(outputFile); | |
} | |
using (PsdImage image = (PsdImage)Image.Load(outputFile)) | |
{ | |
AssertAreEqual(2, image.Layers.Length); | |
ShapeLayer shapeLayer = image.Layers[1] as ShapeLayer; | |
ColorFillSettings internalFill = shapeLayer.Fill as ColorFillSettings; | |
IStrokeSettings strokeSettings = shapeLayer.Stroke; | |
ColorFillSettings strokeFill = shapeLayer.Stroke.Fill as ColorFillSettings; | |
AssertAreEqual(1, shapeLayer.Path.GetItems().Length); // 1 Shape | |
AssertAreEqual(3, shapeLayer.Path.GetItems()[0].GetItems().Length); // 3 knots in a shape | |
AssertAreEqual(-16127182, internalFill.Color.ToArgb()); // ff09eb32 | |
AssertAreEqual(7.41, strokeSettings.Size); | |
AssertAreEqual(false, strokeSettings.Enabled); | |
AssertAreEqual(StrokePosition.Center, strokeSettings.LineAlignment); | |
AssertAreEqual(LineCapType.ButtCap, strokeSettings.LineCap); | |
AssertAreEqual(LineJoinType.MiterJoin, strokeSettings.LineJoin); | |
AssertAreEqual(-16777216, strokeFill.Color.ToArgb()); // ff000000 | |
} | |
PathShape GenerateNewShape(Size imageSize) | |
{ | |
var newShape = new PathShape(); | |
PointF point1 = new PointF(20, 100); | |
PointF point2 = new PointF(200, 100); | |
PointF point3 = new PointF(300, 10); | |
BezierKnotRecord[] bezierKnots = new BezierKnotRecord[] | |
{ | |
new BezierKnotRecord() | |
{ | |
IsLinked = true, | |
Points = new Point[3] | |
{ | |
PointFToResourcePoint(point1, imageSize), | |
PointFToResourcePoint(point1, imageSize), | |
PointFToResourcePoint(point1, imageSize), | |
} | |
}, | |
new BezierKnotRecord() | |
{ | |
IsLinked = true, | |
Points = new Point[3] | |
{ | |
PointFToResourcePoint(point2, imageSize), | |
PointFToResourcePoint(point2, imageSize), | |
PointFToResourcePoint(point2, imageSize), | |
} | |
}, | |
new BezierKnotRecord() | |
{ | |
IsLinked = true, | |
Points = new Point[3] | |
{ | |
PointFToResourcePoint(point3, imageSize), | |
PointFToResourcePoint(point3, imageSize), | |
PointFToResourcePoint(point3, imageSize), | |
} | |
}, | |
}; | |
newShape.SetItems(bezierKnots); | |
return newShape; | |
} | |
Point PointFToResourcePoint(PointF point, Size imageSize) | |
{ | |
return new Point( | |
(int)Math.Round(point.Y * (ImgToPsdRatio / imageSize.Height)), | |
(int)Math.Round(point.X * (ImgToPsdRatio / imageSize.Width))); | |
} | |
void AssertAreEqual(object expected, object actual, string message = null) | |
{ | |
if (!object.Equals(expected, actual)) | |
{ | |
throw new Exception(message ?? "Objects are not equal."); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 = "Stroke.psd"; | |
string exportPath = "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; | |
var patternData = resource.Patterns[0]; | |
patternData.PatternId = guid.ToString(); | |
patternData.Name = "$$$/Presets/Patterns/HorizontalLine1=Horizontal Line 9"; | |
patternData.SetPattern(newPattern, newPatternBounds); | |
} | |
} | |
var settings = (PatternFillSettings) patternStroke.FillSettings; | |
settings.PatternName = "$$$/Presets/Patterns/HorizontalLine1=Horizontal Line 9"; | |
settings.PatternId = guid.ToString(); | |
settings.PatternData = newPattern; | |
settings.PatternWidth = newPatternBounds.Width; | |
settings.PatternHeight = newPatternBounds.Height; | |
im.Save(exportPath); | |
} | |
// Test file after edit | |
using (var im = (PsdImage)Image.Load(exportPath, 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; | |
var patternData = resource.Patterns[0]; | |
if ((newPatternBounds != new Rectangle(0, 0, patternData.Width, patternData.Height)) || | |
(patternData.PatternId != guid.ToString().ToUpperInvariant()) || | |
(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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 = "WithoutVibrance.psd"; | |
string outputFileNamePsd = "out_VibranceLayer.psd"; | |
string outputFileNamePng = "out_VibranceLayer.png"; | |
using (PsdImage image = (PsdImage) Image.Load(sourceFileName)) | |
{ | |
// Creating a new VibranceLayer | |
VibranceLayer vibranceLayer = image.AddVibranceAdjustmentLayer(); | |
vibranceLayer.Vibrance = 50; | |
vibranceLayer.Saturation = 100; | |
image.Save(outputFileNamePsd); | |
image.Save(outputFileNamePng, new PngOptions()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 = "rect2_color.pdf"; | |
ImageOptionsBase pdfOptions = new PdfOptions(); | |
using (AiImage image = (AiImage)Image.Load(sourceFileName)) | |
{ | |
image.Save(outFileName, pdfOptions); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled 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 outFileNamePdfA1a = "rect2_color.pdf"; | |
var pdfOptionsPdfA1a = new PdfOptions(); | |
pdfOptionsPdfA1a.PdfCoreOptions = new PdfCoreOptions(); | |
pdfOptionsPdfA1a.PdfCoreOptions.PdfCompliance = PdfComplianceVersion.PdfA1a; | |
using (AiImage image = (AiImage)Image.Load(sourceFileName)) | |
{ | |
image.Save(outFileNamePdfA1a, pdfOptionsPdfA1a); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 CreatingVectorPathExample(string outputPsd = "outputPsd.psd") | |
{ | |
using (var psdImage = (PsdImage)Image.Create(new PsdOptions() { Source = new StreamSource(new MemoryStream()), }, 500, 500)) | |
{ | |
FillLayer layer = FillLayer.CreateInstance(FillType.Color); | |
psdImage.AddLayer(layer); | |
VectorPath vectorPath = VectorDataProvider.CreateVectorPathForLayer(layer); | |
vectorPath.FillColor = Color.IndianRed; | |
PathShape shape = new PathShape(); | |
shape.Points.Add(new BezierKnot(new PointF(50, 150), true)); | |
shape.Points.Add(new BezierKnot(new PointF(100, 200), true)); | |
shape.Points.Add(new BezierKnot(new PointF(0, 200), true)); | |
vectorPath.Shapes.Add(shape); | |
VectorDataProvider.UpdateLayerFromVectorPath(layer, vectorPath, true); | |
psdImage.Save(outputPsd); | |
} | |
} | |
#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) | |
{ | |
ValidateLayer(psdLayer); | |
Size imageSize = psdLayer.Container.Size; | |
VectorPathDataResource pathResource = FindVectorPathDataResource(psdLayer, true); | |
SoCoResource socoResource = FindSoCoResource(psdLayer, true); | |
VectorPath vectorPath = new VectorPath(pathResource, imageSize); | |
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="imageSize">The image size to correct converting point coordinates.</param> | |
public static void UpdateLayerFromVectorPath(Layer psdLayer, VectorPath vectorPath, bool createIfNotExist = false) | |
{ | |
ValidateLayer(psdLayer); | |
VectorPathDataResource pathResource = FindVectorPathDataResource(psdLayer, createIfNotExist); | |
VogkResource vogkResource = FindVogkResource(psdLayer, createIfNotExist); | |
SoCoResource socoResource = FindSoCoResource(psdLayer, createIfNotExist); | |
Size imageSize = psdLayer.Container.Size; | |
UpdateResources(pathResource, vogkResource, socoResource, vectorPath, imageSize); | |
ReplaceVectorPathDataResourceInLayer(psdLayer, pathResource, vogkResource, socoResource); | |
} | |
/// <summary> | |
/// Removes the vector path data from input layer. | |
/// </summary> | |
/// <param name="psdLayer">The psd layer.</param> | |
public static void RemoveVectorPathDataFromLayer(Layer psdLayer) | |
{ | |
List<LayerResource> oldResources = new List<LayerResource>(psdLayer.Resources); | |
List<LayerResource> newResources = new List<LayerResource>(); | |
for (int i = 0; i < oldResources.Count; i++) | |
{ | |
LayerResource resource = oldResources[i]; | |
if (resource is VectorPathDataResource || resource is VogkResource || resource is SoCoResource) | |
{ | |
continue; | |
} | |
else | |
{ | |
newResources.Add(resource); | |
} | |
} | |
psdLayer.Resources = newResources.ToArray(); | |
} | |
/// <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> | |
/// <param name="imageSize">The image size to correct converting point coordinates.</param> | |
private static void UpdateResources(VectorPathDataResource pathResource, VogkResource vogkResource, SoCoResource socoResource, VectorPath vectorPath, Size imageSize) | |
{ | |
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(imageSize)); | |
originSettings.Add(new VectorShapeOriginSettings() { IsShapeInvalidated = true, OriginIndex = 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 pathResourceExist = false; | |
bool vogkResourceExist = false; | |
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; | |
pathResourceExist = true; | |
} | |
else if (resource is VogkResource) | |
{ | |
resources[i] = vogkResource; | |
vogkResourceExist = true; | |
} | |
else if (resource is SoCoResource) | |
{ | |
resources[i] = socoResource; | |
socoResourceExist = true; | |
} | |
} | |
if (!pathResourceExist) | |
{ | |
resources.Add(pathResource); | |
} | |
if (!vogkResourceExist) | |
{ | |
resources.Add(vogkResource); | |
} | |
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> | |
/// <param name="createIfNotExist">If resource not exists, then for <see cref="true"/> creates a new resource, otherwise return <see cref="null"/>.</param> | |
/// <returns>The <see cref="VectorPathDataResource"/> resource.</returns> | |
private static VectorPathDataResource FindVectorPathDataResource(Layer psdLayer, bool createIfNotExist = false) | |
{ | |
VectorPathDataResource pathResource = null; | |
foreach (var resource in psdLayer.Resources) | |
{ | |
if (resource is VectorPathDataResource) | |
{ | |
pathResource = (VectorPathDataResource)resource; | |
break; | |
} | |
} | |
if (createIfNotExist && pathResource == null) | |
{ | |
pathResource = new VmskResource(); | |
} | |
return pathResource; | |
} | |
/// <summary> | |
/// Finds the <see cref="VogkResource"/> resource in input layer resources. | |
/// </summary> | |
/// <param name="psdLayer">The psd layer.</param> | |
/// <param name="createIfNotExist">If resource not exists, then for <see cref="true"/> creates a new resource, otherwise return <see cref="null"/>.</param> | |
/// <returns>The <see cref="VogkResource"/> resource.</returns> | |
private static VogkResource FindVogkResource(Layer psdLayer, bool createIfNotExist = false) | |
{ | |
VogkResource vogkResource = null; | |
foreach (var resource in psdLayer.Resources) | |
{ | |
if (resource is VogkResource) | |
{ | |
vogkResource = (VogkResource)resource; | |
break; | |
} | |
} | |
if (createIfNotExist && vogkResource == null) | |
{ | |
vogkResource = new VogkResource(); | |
} | |
return vogkResource; | |
} | |
/// <summary> | |
/// Finds the <see cref="SoCoResource"/> resource in input layer resources. | |
/// </summary> | |
/// <param name="psdLayer">The psd layer.</param> | |
/// <param name="createIfNotExist">If resource not exists, then for <see cref="true"/> creates a new resource, otherwise return <see cref="null"/>.</param> | |
/// <returns>The <see cref="SoCoResource"/> resource.</returns> | |
private static SoCoResource FindSoCoResource(Layer psdLayer, bool createIfNotExist = false) | |
{ | |
SoCoResource socoResource = null; | |
foreach (var resource in psdLayer.Resources) | |
{ | |
if (resource is SoCoResource) | |
{ | |
socoResource = (SoCoResource)resource; | |
break; | |
} | |
} | |
if (createIfNotExist && socoResource == null) | |
{ | |
socoResource = new SoCoResource(); | |
} | |
return socoResource; | |
} | |
/// <summary> | |
/// Validates the layer to work with <see cref="VectorDataProvider"/> class. | |
/// </summary> | |
/// <param name="layer"></param> | |
/// <exception cref="ArgumentNullException"></exception> | |
private static void ValidateLayer(Layer layer) | |
{ | |
if (layer == null) | |
{ | |
throw new ArgumentNullException("The layer is NULL."); | |
} | |
if (layer.Container == null || layer.Container.Size.IsEmpty) | |
{ | |
throw new ArgumentNullException("The layer should have a Container with no empty size."); | |
} | |
} | |
} | |
/// <summary> | |
/// The Bezier curve knot, it contains one anchor point and two control points. | |
/// </summary> | |
public class BezierKnot | |
{ | |
/// <summary> | |
/// Image to path point ratio. | |
/// </summary> | |
private const int ImgToPsdRatio = 256 * 65535; | |
/// <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> | |
/// <param name="imageSize">The image size to correct converting point coordinates.</param> | |
public BezierKnot(BezierKnotRecord bezierKnotRecord, Size imageSize) | |
{ | |
this.IsLinked = bezierKnotRecord.IsLinked; | |
this.ControlPoint1 = ResourcePointToPointF(bezierKnotRecord.Points[0], imageSize); | |
this.AnchorPoint = ResourcePointToPointF(bezierKnotRecord.Points[1], imageSize); | |
this.ControlPoint2 = ResourcePointToPointF(bezierKnotRecord.Points[2], imageSize); | |
} | |
/// <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> | |
/// <param name="imageSize">The image size to correct converting point coordinates.</param> | |
/// <returns>The instance of <see cref="BezierKnotRecord"/> based on this instance.</returns> | |
public BezierKnotRecord ToBezierKnotRecord(bool isClosed, Size imageSize) | |
{ | |
BezierKnotRecord record = new BezierKnotRecord(); | |
record.Points = new Point[] | |
{ | |
PointFToResourcePoint(this.ControlPoint1, imageSize), | |
PointFToResourcePoint(this.AnchorPoint, imageSize), | |
PointFToResourcePoint(this.ControlPoint2, imageSize), | |
}; | |
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> | |
/// <param name="imageSize">The image size to correct converting point coordinates.</param> | |
/// <returns>The converted to normal point.</returns> | |
private static PointF ResourcePointToPointF(Point point, Size imageSize) | |
{ | |
return new PointF(point.Y / (ImgToPsdRatio / imageSize.Width), point.X / (ImgToPsdRatio / imageSize.Height)); | |
} | |
/// <summary> | |
/// Converts normal point values to resource point. | |
/// </summary> | |
/// <param name="point">The point.</param> | |
/// <param name="imageSize">The image size to correct converting point coordinates.</param> | |
/// <returns>The point with values for resource.</returns> | |
private static Point PointFToResourcePoint(PointF point, Size imageSize) | |
{ | |
return new Point((int)Math.Round(point.Y * (ImgToPsdRatio / imageSize.Height)), (int)Math.Round(point.X * (ImgToPsdRatio / imageSize.Width))); | |
} | |
} | |
/// <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> | |
/// <param name="imageSize">The image size to correct converting point coordinates.</param> | |
public PathShape(LengthRecord lengthRecord, List<BezierKnotRecord> bezierKnotRecords, Size imageSize) | |
: this() | |
{ | |
this.IsClosed = lengthRecord.IsClosed; | |
this.PathOperations = lengthRecord.PathOperations; | |
this.ShapeIndex = lengthRecord.ShapeIndex; | |
this.InitFromResources(bezierKnotRecords, imageSize); | |
} | |
/// <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> | |
/// <param name="imageSize">The image size to correct converting point coordinates.</param> | |
/// <returns>Returns one <see cref="LengthRecord"/> and <see cref="BezierKnotRecord"/> for each point in this instance.</returns> | |
public IEnumerable<VectorPathRecord> ToVectorPathRecords(Size imageSize) | |
{ | |
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, imageSize)); | |
} | |
return shapeRecords; | |
} | |
/// <summary> | |
/// Initializes a values based on input records. | |
/// </summary> | |
/// <param name="bezierKnotRecords">The bezier knot records.</param> | |
/// <param name="imageSize">The image size to correct converting point coordinates.</param> | |
private void InitFromResources(IEnumerable<BezierKnotRecord> bezierKnotRecords, Size imageSize) | |
{ | |
List<BezierKnot> newPoints = new List<BezierKnot>(); | |
foreach (var record in bezierKnotRecords) | |
{ | |
newPoints.Add(new BezierKnot(record, imageSize)); | |
} | |
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> | |
/// <param name="imageSize">The image size to correct converting point coordinates.</param> | |
public VectorPath(VectorPathDataResource vectorPathDataResource, Size imageSize) | |
{ | |
this.InitFromResource(vectorPathDataResource, imageSize); | |
} | |
/// <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> | |
/// Gets or sets 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> | |
/// <param name="imageSize">The image size to correct converting point coordinates.</param> | |
private void InitFromResource(VectorPathDataResource resource, Size imageSize) | |
{ | |
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, imageSize)); | |
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, imageSize)); | |
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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 outputUpdated = "output_updated.psd"; | |
using (PsdImage im = (PsdImage)Image.Load(source)) | |
{ | |
SharpenSmartFilter sharpenFilter = new SharpenSmartFilter(); | |
Layer regularLayer = im.Layers[1]; | |
for (int i = 0; i < 3; i++) | |
{ | |
sharpenFilter.Apply(regularLayer); | |
} | |
im.Save(outputUpdated); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string sourceFile = "warp_flag.psd"; | |
string outputFile = "total.png"; | |
using (var psdImage = (PsdImage)Image.Load(sourceFile, new PsdLoadOptions() { AllowWarpRepaint = true, LoadEffectsResource = true })) | |
{ | |
psdImage.Save(outputFile, new PngOptions | |
{ | |
ColorType = PngColorType.TruecolorWithAlpha | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string sourceFile = "warp_text_wave.psd"; | |
string outputFile = "total.png"; | |
using (var psdImage = (PsdImage)Image.Load(sourceFile, new PsdLoadOptions() { AllowWarpRepaint = true, LoadEffectsResource = true })) | |
{ | |
psdImage.Save(outputFile, new PngOptions | |
{ | |
ColorType = PngColorType.TruecolorWithAlpha | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string sourceFile = "warp_flag.psd"; | |
string outputFile = "total.png"; | |
using (var psdImage = (PsdImage)Image.Load(sourceFile, new PsdLoadOptions() { AllowWarpRepaint = true, LoadEffectsResource = true })) | |
{ | |
var smartLayer = (SmartObjectLayer)psdImage.Layers[0]; | |
WarpParams warpParams = smartLayer.WarpParams;]; | |
WarpParams warpParams = smartLayer.WarpParams; | |
if (warpParams.Style == WarpStyles.Flag) | |
{ | |
warpParams.Style = WarpStyles.Wave; | |
warpParams.Value = 20; | |
} | |
psdImage.Save(outputFile, new PngOptions | |
{ | |
ColorType = PngColorType.TruecolorWithAlpha | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string sourceFile = "smart_object.psd"; | |
string outputFile = "total.png"; | |
using (var psdImage = (PsdImage)Image.Load(sourceFile, new PsdLoadOptions() { AllowWarpRepaint = true, LoadEffectsResource = true })) | |
{ | |
// The smart object without Warp effect | |
var smartLayer = (SmartObjectLayer)psdImage.Layers[0]; | |
// It gets structure for warp effect | |
WarpParams warpParams = smartLayer.WarpParams; | |
// It sets parameters for warp effect | |
warpParams.Style = WarpStyles.Arc; | |
warpParams.Value = 10; | |
psdImage.Save(outputFile, new PngOptions | |
{ | |
ColorType = PngColorType.TruecolorWithAlpha | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string sourceFile = "smart_object.psd"; | |
string outputFile = "total.png"; | |
using (var psdImage = (PsdImage)Image.Load(sourceFile, new PsdLoadOptions() { AllowWarpRepaint = true, LoadEffectsResource = true })) | |
{ | |
// The smart object without Warp effect | |
var smartLayer = (SmartObjectLayer)psdImage.Layers[0]; | |
// It gets structure for warp effect | |
WarpParams warpParams = smartLayer.WarpParams; | |
// It sets parameters for warp effect | |
warpParams.Style = WarpStyles.Custom; | |
warpParams.MeshPoints[2].Y += 70; | |
psdImage.Save(outputFile, new PngOptions | |
{ | |
ColorType = PngColorType.TruecolorWithAlpha | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string sourceFile = "warp_text.psd"; | |
string outputFile = "total.png"; | |
using (var psdImage = (PsdImage)Image.Load(sourceFile, new PsdLoadOptions() { AllowWarpRepaint = true, LoadEffectsResource = true })) | |
{ | |
// The text layer without Warp effect | |
var textLayer = (TextLayer)psdImage.Layers[0]; | |
// It gets structure for warp effect | |
WarpParams warpParams = textLayer.WarpParams; | |
// It sets parameters for warp effect | |
warpParams.Style = WarpStyles.Wave; | |
warpParams.Value = 10; | |
psdImage.Save(outputFile, new PngOptions | |
{ | |
ColorType = PngColorType.TruecolorWithAlpha | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 = "GradientOverlay.psd"; | |
string exportPath = "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(exportPath, 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.0); | |
AssertIsTrue(transparencyPoint.Location == 0); | |
transparencyPoint = fillSettings.TransparencyPoints[1]; | |
AssertIsTrue(transparencyPoint.MedianPointLocation == 50); | |
AssertIsTrue(transparencyPoint.Opacity == 100.0); | |
AssertIsTrue(transparencyPoint.Location == 2315); | |
transparencyPoint = fillSettings.TransparencyPoints[2]; | |
AssertIsTrue(transparencyPoint.MedianPointLocation == 25); | |
AssertIsTrue(transparencyPoint.Opacity == 25.0); | |
AssertIsTrue(transparencyPoint.Location == 4096); | |
} | |
catch (Exception e) | |
{ | |
string ex = e.StackTrace; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 = "PatternOverlay.psd"; | |
string exportPath = "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(exportPath, 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 ((newPatternBounds != new Rectangle(0, 0, resource.Width, resource.Height)) || | |
(resource.PatternId != guid.ToString()) || | |
((resource.Name + "\0") != newPatternName) | |
) | |
{ | |
throw new Exception("Pattern was set wrong"); | |
} | |
} | |
catch (Exception e) | |
{ | |
string ex = e.StackTrace; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 = "Stroke.psd"; | |
string exportPath = "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(exportPath, 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 ((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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 inputFilePath = "psdnet414_3.psd"; | |
string output = "out_psdnet414_3.psd"; | |
int resLength = 1144; | |
int maskLength = 369; | |
void AssertAreEqual(object expected, object actual, string message = null) | |
{ | |
if (!object.Equals(expected, actual)) | |
{ | |
throw new FormatException(message ?? "Objects are not equal."); | |
} | |
} | |
using (var psdImage = (PsdImage)Image.Load(inputFilePath)) | |
{ | |
FXidResource fXidResource = (FXidResource)psdImage.GlobalLayerResources[3]; | |
AssertAreEqual(resLength, fXidResource.Length); | |
foreach (var maskData in fXidResource.FilterEffectMasks) | |
{ | |
AssertAreEqual(maskLength, maskData.Length); | |
} | |
psdImage.Save(output); | |
} | |
// check after saving | |
using (var psdImage = (PsdImage)Image.Load(output)) | |
{ | |
FXidResource fXidResource = (FXidResource)psdImage.GlobalLayerResources[3]; | |
AssertAreEqual(resLength, fXidResource.Length); | |
foreach (var maskData in fXidResource.FilterEffectMasks) | |
{ | |
AssertAreEqual(maskLength, maskData.Length); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 SourceDir = RunExamples.GetDataDir_PSD(); | |
string OutputDir = RunExamples.GetDataDir_Output(); | |
// This example shows how to get and set new Transform and OriginBoxCorners properties | |
// of ShapeOriginSettings in the Vogk resource of FillLayer in the PSD file | |
string sourceFileName = "vectorShape_25_50.psd"; | |
string outputPath = "result.psd"; | |
VectorShapeOriginSettings originalSetting; | |
const int layerIndex = 0; | |
// Load the original image | |
using (PsdImage image = (PsdImage)Image.Load(sourceFileName)) | |
{ | |
AssertIsTrue(layerIndex < image.Layers.Length); | |
var layer = image.Layers[layerIndex]; | |
AssertIsTrue(layer is FillLayer); | |
var resource = GetVogkResource((FillLayer)layer); | |
AssertAreEqual(1, resource.ShapeOriginSettings.Length); | |
// Assert after reading | |
var setting = resource.ShapeOriginSettings[0]; | |
AssertAreEqual(false, setting.IsShapeInvalidatedPresent); | |
AssertAreEqual(false, setting.IsOriginRadiiRectanglePresent); | |
AssertAreEqual(true, setting.IsOriginIndexPresent); | |
AssertAreEqual(0, setting.OriginIndex); | |
AssertAreEqual(true, setting.IsOriginTypePresent); | |
AssertAreEqual(5, setting.OriginType); | |
AssertAreEqual(true, setting.IsOriginShapeBBoxPresent); | |
AssertAreEqual(Rectangle.FromLeftTopRightBottom(3, 7, 10, 22), setting.OriginShapeBox.Bounds); | |
AssertAreEqual(true, setting.IsOriginResolutionPresent); | |
AssertAreEqual(300d, setting.OriginResolution); | |
// Assert new properties | |
AssertAreEqual(true, setting.IsTransformPresent); | |
AssertAreEqual(0d, setting.Transform.Tx); | |
AssertAreEqual(0d, setting.Transform.Ty); | |
AssertAreEqual(0.050000000000000003d, setting.Transform.Xx); | |
AssertAreEqual(0d, setting.Transform.Yx); | |
AssertAreEqual(0d, setting.Transform.Xy); | |
AssertAreEqual(0.1d, setting.Transform.Yy); | |
AssertAreEqual(true, setting.IsOriginBoxCornersPresent); | |
AssertAreEqual(2.9000000000000004d, setting.OriginBoxCorners[0]); | |
AssertAreEqual(7.3000000000000007d, setting.OriginBoxCorners[1]); | |
AssertAreEqual(10.450000000000001d, setting.OriginBoxCorners[2]); | |
AssertAreEqual(7.3000000000000007d, setting.OriginBoxCorners[3]); | |
AssertAreEqual(10.450000000000001d, setting.OriginBoxCorners[4]); | |
AssertAreEqual(22.400000000000002d, setting.OriginBoxCorners[5]); | |
AssertAreEqual(2.9000000000000004d, setting.OriginBoxCorners[6]); | |
AssertAreEqual(22.400000000000002d, setting.OriginBoxCorners[7]); | |
// Set new properties | |
originalSetting = resource.ShapeOriginSettings[0]; | |
originalSetting.Transform.Tx = 0.2d; | |
originalSetting.Transform.Ty = 0.3d; | |
originalSetting.Transform.Xx = 0.4d; | |
originalSetting.Transform.Xy = 0.5d; | |
originalSetting.Transform.Yx = 0.6d; | |
originalSetting.Transform.Yy = 0.7d; | |
originalSetting.OriginBoxCorners = new double[8] { 9, 8, 7, 6, 5, 4, 3, 2 }; | |
// Save this PSD image with changed propeties. | |
image.Save(outputPath, new PsdOptions(image)); | |
} | |
// Load the saved PSD image with changed propeties. | |
using (PsdImage image = (PsdImage)Image.Load(outputPath)) | |
{ | |
var layer = image.Layers[layerIndex]; | |
AssertIsTrue(layer is FillLayer); | |
var resource = GetVogkResource((FillLayer)layer); | |
AssertAreEqual(1, resource.ShapeOriginSettings.Length); | |
// Assert that properties are saved and loaded correctly | |
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); | |
AssertAreEqual(true, setting.IsTransformPresent); | |
AssertAreEqual(0.2d, setting.Transform.Tx); | |
AssertAreEqual(0.3d, setting.Transform.Ty); | |
AssertAreEqual(0.4d, setting.Transform.Xx); | |
AssertAreEqual(0.5d, setting.Transform.Xy); | |
AssertAreEqual(0.6d, setting.Transform.Yx); | |
AssertAreEqual(0.7d, setting.Transform.Yy); | |
AssertAreEqual(true, setting.IsOriginBoxCornersPresent); | |
AssertAreEqual(originalSetting.OriginBoxCorners[0], setting.OriginBoxCorners[0]); | |
AssertAreEqual(originalSetting.OriginBoxCorners[1], setting.OriginBoxCorners[1]); | |
AssertAreEqual(originalSetting.OriginBoxCorners[2], setting.OriginBoxCorners[2]); | |
AssertAreEqual(originalSetting.OriginBoxCorners[3], setting.OriginBoxCorners[3]); | |
AssertAreEqual(originalSetting.OriginBoxCorners[4], setting.OriginBoxCorners[4]); | |
AssertAreEqual(originalSetting.OriginBoxCorners[5], setting.OriginBoxCorners[5]); | |
AssertAreEqual(originalSetting.OriginBoxCorners[6], setting.OriginBoxCorners[6]); | |
AssertAreEqual(originalSetting.OriginBoxCorners[7], setting.OriginBoxCorners[7]); | |
} | |
VogkResource GetVogkResource(FillLayer layer) | |
{ | |
if (layer == null) | |
{ | |
throw new PsdImageArgumentException("The parameter layer should not be null."); | |
} | |
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 PsdImageException("VogkResource not found."); | |
} | |
return resource; | |
} | |
void AssertIsTrue(bool condition) | |
{ | |
if (!condition) | |
{ | |
throw new FormatException(string.Format("Expected true")); | |
} | |
} | |
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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 hidden or bidirectional Unicode text that may be interpreted or compiled 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: | |