原創|產品更新|編輯:李顯亮|2020-04-28 10:18:11.390|閱讀 287 次
概述:.NET版Aspose.PSD迎來了4月的最新更新!新增了如下九大新功能:支持“向量原始數據”資源、支持lclrResource(工作表顏色設置)、LengthRecord數據中的支持屬性、支持圖像部分資源#1010背景顏色、在運行時添加填充層,支持圖像部分資源#1009邊框信息、支持AI格式文件中的圖層、支持讀取和編輯漸變疊加層效果、漸變疊加層效果的渲染 。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Aspose.PSD for .Net是高級PSD和入門級AI文件格式操作API,允許創建和編輯Photoshop文件,并提供更新圖層屬性,添加水印,執行圖形操作或將一種文件格式轉換為另一種文件的功能,沒有任何Adobe Photoshop或Adobe Illustrator依賴項。
令人興奮的是,.NET版Aspose.PSD迎來了4月的最新更新!新增了如下六大新功能:
>>你可以點擊這里下載Aspose.PSD for .NET v20.4測試體驗
| key | 概述 | 類別 |
|---|---|---|
| PSDNET-567 | 支持“向量原始數據”資源 | 新功能 |
| PSDNET-373 | 支持lclrResource(工作表顏色設置) | 新功能 |
| PSDNET-563 | LengthRecord數據中的支持屬性。(路徑操作(布爾操作),層中形狀的索引,貝塞爾結記錄的計數) | 新功能 |
| PSDNET-425 | 支持圖像部分資源#1010背景顏色 | 新功能 |
| PSDNET-530 | 在運行時添加填充層 | 新功能 |
| PSDNET-424 | 支持圖像部分資源#1009邊框信息 | 新功能 |
| PSDNET-592 | 支持AI格式文件中的圖層 | 新功能 |
| PSDNET-256 | 支持讀取和編輯漸變疊加層效果 | 新功能 |
| PSDNET-257 | 漸變疊加層效果的渲染 | 新功能 |
| PSDNET-585 | GradientOverlayEffect.BlendMode屬性更改不會在Photoshop中顯示 | Bug修復 |
| PSDNET-561 | 修復了使用灰度ColorMode和每通道16位將PSD圖像保存為灰度PSD格式的問題 | Bug修復 |
| PSDNET-560 | 修復了使用灰度ColorMode和每通道16位將PSD圖像保存為PNG格式的問題 | Bug修復 |
// VogkResource Support
static void ExampleOfVogkResourceSupport()
{
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);
}
}
static 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; }
static 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; } } } } string sourceFilePath = "AllLclrResourceColors.psd"; string outputFilePath = "AllLclrResourceColorsReversed.psd"; // In the file colors of layers' highlighting are in this order SheetColorHighlightEnum[] sheetColors = 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. using (PsdImage img = (PsdImage)Image.Load(sourceFilePath)) { CheckSheetColorsAndRerverse(sheetColors, img); img.Save(outputFilePath, new PsdOptions()); } using (PsdImage img = (PsdImage)Image.Load(outputFilePath)) { // Colors should be reversed Array.Reverse(sheetColors); CheckSheetColorsAndRerverse(sheetColors, img); }
string fileName = "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("out_" + fileName);
}
string sourceFile = "input.psd";
string outputFile = "output.psd";
using (var image = (PsdImage)Image.Load(sourceFile))
{
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(outputFile);
}
string outputPsd = "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(outputPsd);
}
string sourceFile = "input.psd";
string outputFile = "output.psd";
using (var image = (PsdImage)Image.Load(sourceFile))
{
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(outputFile);
}
void AssertIsTrue(bool condition, string message)
{
if (!condition)
{
throw new FormatException(message);
}
}
string sourceFileName = "form_8_2l3_7.ai";
string outputFileName = "form_8_2l3_7_export";
using (AiImage image = (AiImage)Image.Load(sourceFileName))
{
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(outputFileName + ".psd", new PsdOptions());
image.Save(outputFileName + ".png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
}
// Creates/Gets and edits the gradient overlay effect in a layer.
using (var psdImage = this.LoadFile("psdnet256.psd", 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("psdnet256.psd_output.psd");
}
string srcFile = "gradientOverlayEffect.psd";
string outputPng = "output.png";
string outputPsd = "output.psd";
using (var psdImage = (PsdImage)Image.Load(srcFile, new PsdLoadOptions() { LoadEffectsResource = true }))
{
psdImage.Save(outputPng, new PngOptions());
psdImage.Save(outputPsd);
}
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn