彩票走势图

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

原创|产品更新|编辑:李显亮|2020-12-03 09:48:35.263|阅读 255 次

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

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

Aspose.PSD for .Net是高级PSD和入门级AI文件格式操作API,允许创建和编辑Photoshop文件,并提供更新图层属性,添加水印,执行图形操作或将一种文件格式转换为另一种文件的功能,没有任何Adobe Photoshop或Adobe Illustrator依赖项。

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技术交流群(761297826),我们很高兴为您提供查询和咨询

标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP