PSD文档处理工具Aspose.PSD最新优化更新,示例解析教你1分钟学会新功能

Aspose.PSD for .Net更新至新版本v20.11,增加了在PSD图像中复制智能对象层的功能,修复无法加载Psd等问题,欢迎下载体验。

Aspose.PSD for .Net更新至新版本v20.11,增加了在PSD图像中复制智能对象层的功能,修复无法加载Psd等问题。

>>你可以点击这里下载Aspose.PSD for .NET v20.11测试体验。(安装包仅提供部分功能,并设置限制,如需试用完整功能请申请免费授权)

17周年庆来啦!整合所有格式API处理控件Aspose.Total永久授权火热促销中,新购乐享85折起!联系客服立马1分钟了解全部!

具体更新内容

key 概述 类别
PSDNET-713 果不将PSD保存为文件,Aspose.PSD不能将PSD转换为其他颜色模式/ BitDepth 新功能
PSDNET-754 增加了在PSD图像中复制智能对象层的功能 新功能
PSDNET-267 带有图层效果加载和保存PSD文件的异常 Bug修复
PSDNET-579 方法“ Image.LoadRawData”抛出NullPointer异常 Bug修复
PSDNET-741 尝试打开文件时抛出ImageLoadException Bug修复
PSDNET-744 Aspose.PSD 20.10:无法加载Psd Bug修复

新功能解析

PSDNET-754——增加了在PSD图像中复制智能对象层的功能

    string dataDir = "PSDNET754_1\";            string outputDir = dataDir + "output\";            // These examples demonstrate how to copy smart object layers in a PSD image.            ExampleOfCopingSmartObjectLayer("r-embedded-psd");            ExampleOfCopingSmartObjectLayer("r-embedded-png");            ExampleOfCopingSmartObjectLayer("r-embedded-transform");            ExampleOfCopingSmartObjectLayer("new_panama-papers-8-trans4");            void ExampleOfCopingSmartObjectLayer(string fileName)            {                int layerNumber = 0; // The layer number to copy                string filePath = dataDir + fileName + ".psd";                string outputFilePath = outputDir + fileName + "_copy_" + layerNumber;                string pngOutputPath = outputFilePath + ".png";                string psdOutputPath = outputFilePath + ".psd";                using (PsdImage image = (PsdImage)Image.Load(filePath))                {                    var smartObjectLayer = (SmartObjectLayer)image.Layers[layerNumber];                    var newLayer = smartObjectLayer.NewSmartObjectViaCopy();                    newLayer.IsVisible = false;                    AssertIsTrue(object.ReferenceEquals(newLayer, image.Layers[layerNumber + 1]));                    AssertIsTrue(object.ReferenceEquals(smartObjectLayer, image.Layers[layerNumber]));                    var duplicatedLayer = smartObjectLayer.DuplicateLayer();                    duplicatedLayer.DisplayName = smartObjectLayer.DisplayName + " shared image";                    AssertIsTrue(object.ReferenceEquals(newLayer, image.Layers[layerNumber + 2]));                    AssertIsTrue(object.ReferenceEquals(duplicatedLayer, image.Layers[layerNumber + 1]));                    AssertIsTrue(object.ReferenceEquals(smartObjectLayer, image.Layers[layerNumber]));                    using (var innerImage = (RasterImage)smartObjectLayer.LoadContents(null))                    {                        // Let's invert the embedded smart object image (for an inner PSD image we invert only its first layer)                        InvertImage(innerImage);                        // Let's replace the embedded smart object image in the PSD layer                        smartObjectLayer.ReplaceContents(innerImage);                    }                    // The duplicated layer shares its imbedded image with the original smart object                    // and it should be updated explicitly otherwise its rendering cache remains unchanged.                    // We update every smart object to make sure that the new layer created by NewSmartObjectViaCopy                    // does not share the embedded image with the others.                    image.SmartObjectProvider.UpdateAllModifiedContent();                    image.Save(pngOutputPath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });                    image.Save(psdOutputPath, new PsdOptions(image));                }            }            // Inverts the raster image including the PSD image.            void InvertImage(RasterImage innerImage)            {                var innerPsdImage = innerImage as PsdImage;                if (innerPsdImage != null)                {                    InvertRasterImage(innerPsdImage.Layers[0]);                }                else                {                    InvertRasterImage(innerImage);                }            }            // Inverts the raster image.            void InvertRasterImage(RasterImage innerImage)            {                var pixels = innerImage.LoadArgb32Pixels(innerImage.Bounds);                for (int i = 0; i < pixels.Length; i++) { var pixel = pixels[i]; var alpha = (int)(pixel & 0xff000000); pixels[i] = (~(pixel & 0x00ffffff)) | alpha; } innerImage.SaveArgb32Pixels(innerImage.Bounds, pixels); } void AssertIsTrue(bool condition) { if (!condition) { throw new FormatException(string.Format("Expected true")); } }

PSDNET-713——如果不将PSD保存为文件,Aspose.PSD不能将PSD转换为其他颜色模式/ BitDepth

string dataDir = "PSDNET713_1\";            string outputDir = dataDir + "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;                    Aspose.PSD.Graphics graphics = new Graphics(raster);                    int width = raster.Width;                    int height = raster.Height;                    Rectangle rect = new Rectangle(                        width / 3,                        height / 3,                        width - (2 * (width / 3)) - 1,                        height - (2 * (height / 3)) - 1);                    graphics.DrawRectangle(new Aspose.PSD.Pen(Color.DarkGray, 1), rect);                    image.Save(exportPath);                }                string pngExportPath = Path.ChangeExtension(exportPath, "png");                using (PsdImage image = (PsdImage)Image.Load(exportPath))                {                    image.Save(pngExportPath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });                }            }


还想要更多吗可以点击阅读【2020 · Aspose最新资源整合】查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询
标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年11月1日
下一篇 2020年11月1日

相关推荐

发表回复

登录后才能评论