彩票走势图

图像处理控件Aspose.Imaging v19.6新版亮点示例详解(1)

翻译|产品更新|编辑:李显亮|2019-07-22 10:49:29.913|阅读 119 次

概述:近期发布了Aspose.Imaging for .NET v19.6,JPEG输出中不再保留IMAGINGNET-3351 DPI属性,下面我们一起来探索新版中的新增功能及其工作原理。>>欢迎下载Aspose.Imaging for .NET v19.6体验

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

相关链接:

Aspose.Imaging for .NET一种高级图像处理控件,允许开发人员创建,编辑,绘制或转换图像。图像导出和转换是API核心功能之一,它允许在不安装Photoshop应用程序或任何其他图像编辑器的情况下保存为AdobePhotoshop®本机格式。

近期发布了Aspose.Imaging for .NET v19.6,JPEG输出中不再保留IMAGINGNET-3351 DPI属性,下面我们一起来探索新版中的新增功能及其工作原理。>>欢迎下载Aspose.Imaging for .NET v19.6体验

▲IMAGINGNET-3376 - Backpose Aspose.PSD代码更新到Aspose.Imaging April / 2019

 //支持SoCoResource
    string sourceFileName = "ColorFillLayer.psd";
    string exportPath = "SoCoResource_Edited.psd";
 
    var im = (PsdImage)Image.Load(sourceFileName);
 
    using (im)
    {
        foreach (var layer in im.Layers)
        {
            if (layer is FillLayer)
            {
                var fillLayer = (FillLayer)layer;
                foreach (var resource in fillLayer.Resources)
                {
                    if (resource is SoCoResource)
                    {
                        var socoResource = (SoCoResource)resource;
                        Assert.AreEqual(Color.FromArgb(63, 83, 141), socoResource.Color);
                        socoResource.Color = Color.Red;
                        break;
                    }
                 }
                 break;
             }
            im.Save(exportPath);
        }
    }


 //支持GdFlResource
    string sourceFileName = "ComplexGradientFillLayer.psd";
    string exportPath = "ComplexGradientFillLayer_after.psd";
 
    var im = (PsdImage)Image.Load(sourceFileName);
 
    using (im)
    {
        foreach (var layer in im.Layers)
        {
                    if (layer is FillLayer)
                    {
                        var fillLayer = (FillLayer)layer;
 
                        var resources = fillLayer.Resources;
 
                        foreach (var res in resources)
                        {
                            if (res is GdFlResource)
                            {
                               //阅读
                                var resource = (GdFlResource)res;
 
                                if (resource.AlignWithLayer != false ||
                                (Math.Abs(resource.Angle - 45.0) > 0.001) ||
                                resource.Dither != true ||
                                resource.Reverse != false ||
                                resource.Color != Color.Empty ||
                                Math.Abs(resource.HorizontalOffset - (-39)) > 0.001 ||
                                Math.Abs(resource.VerticalOffset - (-5)) > 0.001 ||
                                resource.TransparencyPoints.Length != 3 ||
                                resource.ColorPoints.Length != 2)
                                {
                                    throw new Exception("Resource Parameters were read wrong");
                                }
 
                                var transparencyPoints = resource.TransparencyPoints;
 
                                if (Math.Abs(100.0 - transparencyPoints[0].Opacity) > 0.25 ||
                                transparencyPoints[0].Location != 0 ||
                                transparencyPoints[0].MedianPointLocation != 50 ||
                                Math.Abs(50.0 - transparencyPoints[1].Opacity) > 0.25 ||
                                transparencyPoints[1].Location != 2048 ||
                                transparencyPoints[1].MedianPointLocation != 50 ||
                                Math.Abs(100.0 - transparencyPoints[2].Opacity) > 0.25 ||
                                transparencyPoints[2].Location != 4096 ||
                                transparencyPoints[2].MedianPointLocation != 50)
                                {
                                    throw new Exception("Gradient Transparency Points were read Wrong");
                                }
 
                                var colorPoints = resource.ColorPoints;
 
                                if (colorPoints[0].Color != Color.FromArgb(203, 64, 140) ||
                                colorPoints[0].Location != 0 ||
                                colorPoints[0].MedianPointLocation != 50 ||
                                colorPoints[1].Color != Color.FromArgb(203, 0, 0) ||
                                colorPoints[1].Location != 4096 ||
                                colorPoints[1].MedianPointLocation != 50)
                                {
                                    throw new Exception("Gradient Color Points were read Wrong");
                                }
 
                                //编辑
                                resource.Angle = 30.0;
                                resource.Dither = false;
                                resource.AlignWithLayer = true;
                                resource.Reverse = true;
                                resource.HorizontalOffset = 25;
                                resource.VerticalOffset = -15;
 
                                var newColorPoints = new List  (resource.ColorPoints);
                                var newTransparencyPoints = new List  (resource.TransparencyPoints);
 
                                newColorPoints.Add(new GradientColorPoint()
                                {
                                    Color = Color.Violet,
                                    Location = 4096,
                                    MedianPointLocation = 75
                                });
 
                                colorPoints[1].Location = 3000;
 
                                newTransparencyPoints.Add(new GradientTransparencyPoint()
                                {
                                    Opacity = 80.0,
                                    Location = 4096,
                                    MedianPointLocation = 25
                                });
 
                                transparencyPoints[2].Location = 3000;
 
                                resource.ColorPoints = newColorPoints.ToArray();
                                resource.TransparencyPoints = newTransparencyPoints.ToArray();
 
                                im.Save(exportPath);
                            }
 
                            break;
                        }
 
                        break;
                    }
                }   
    }


 //支持VmskResource
        static void ExampleOfVmskResourceSupport()
        {
            string sourceFileName = "Rectangle.psd";
            string exportPath = "Rectangle_changed.psd";
 
            var im = (PsdImage)Image.Load(sourceFileName);
 
            using (im)
            {
                var resource = GetVmskResource(im);
 
                //阅读
                if (resource.IsDisabled != false ||
                    resource.IsInverted != false ||
                    resource.IsNotLinked != false ||
                    resource.Paths.Length != 7 ||
                    resource.Paths[0].Type != VectorPathType.PathFillRuleRecord ||
                    resource.Paths[1].Type != VectorPathType.InitialFillRuleRecord ||
                    resource.Paths[2].Type != VectorPathType.ClosedSubpathLengthRecord ||
                    resource.Paths[3].Type != VectorPathType.ClosedSubpathBezierKnotUnlinked ||
                    resource.Paths[4].Type != VectorPathType.ClosedSubpathBezierKnotUnlinked ||
                    resource.Paths[5].Type != VectorPathType.ClosedSubpathBezierKnotUnlinked||
                    resource.Paths[6].Type != VectorPathType.ClosedSubpathBezierKnotUnlinked)
                {
                        throw new Exception("VmskResource was read wrong");
                }
 
                var pathFillRule = (PathFillRuleRecord)resource.Paths[0];
                var initialFillRule = (InitialFillRuleRecord)resource.Paths[1];
                var subpathLength = (LengthRecord)resource.Paths[2];
 
                //路径填充规则不包含任何附加信息
                if (pathFillRule.Type != VectorPathType.PathFillRuleRecord || 
                initialFillRule.Type != VectorPathType.InitialFillRuleRecord ||
                initialFillRule.IsFillStartsWithAllPixels != false ||
                subpathLength.Type != VectorPathType.ClosedSubpathLengthRecord ||
                subpathLength.IsClosed != true ||
                subpathLength.IsOpen != false) 
                {
                    throw new Exception("VmskResource paths were read wrong");
                }
 
                // 编辑
                resource.IsDisabled = true;
                resource.IsInverted = true;
                resource.IsNotLinked = true;
 
                var bezierKnot = (BezierKnotRecord)resource.Paths[3];
                bezierKnot.Points[0] = new Point(0, 0);
 
                bezierKnot = (BezierKnotRecord)resource.Paths[4];
                bezierKnot.Points[0] = new Point(8039797, 10905190);
 
                initialFillRule.IsFillStartsWithAllPixels = true;
                subpathLength.IsClosed = false;
                im.Save(exportPath);
            }         
        }
            static VmskResource GetVmskResource(PsdImage image)
        {
            var layer = image.Layers[1];
 
            VmskResource resource = null;
            var resources = layer.Resources;
            for (int i = 0; i < resources.Length; i++)
            {
                if (resources[i] is VmskResource)
                {
                    resource = (VmskResource) resources[i];
                    break;
                }
            }
 
            if (resource == null)
            {
                throw new Exception("VmskResource not found");
            }
 
            return resource;
        }


//添加填充层支持:颜色填充
    string sourceFileName = "ColorFillLayer.psd";
    string exportPath = "ColorFillLayer_output.psd";
    string exportPathPng = "ColorFillLayer_output.png";
 
    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;
            }
        }
    }


//支持渐变填充层
    string sourceFileName = "ComplexGradientFillLayer.psd";
    string outputFile = "ComplexGradientFillLayer_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.Gradient)
                        {
                            throw new Exception("Wrong Fill Layer");
                        }
 
                        var settings = (IGradientFillSettings)fillLayer.FillSettings;
 
                        if (
                            Math.Abs(settings.Angle - 45) > 0.25 ||
                            settings.Dither != true ||
                            settings.AlignWithLayer != false ||
                            settings.Reverse != false ||
                            Math.Abs(settings.HorizontalOffset - (-39)) > 0.25 ||
                            Math.Abs(settings.VerticalOffset - (-5)) > 0.25 ||
                            settings.TransparencyPoints.Length != 3 ||
                            settings.ColorPoints.Length != 2 ||
                            Math.Abs(100.0 - settings.TransparencyPoints[0].Opacity) > 0.25 ||
                            settings.TransparencyPoints[0].Location != 0 ||
                            settings.TransparencyPoints[0].MedianPointLocation != 50 ||
                            settings.ColorPoints[0].Color != Color.FromArgb(203, 64, 140) ||
                            settings.ColorPoints[0].Location != 0 ||
                            settings.ColorPoints[0].MedianPointLocation != 50)
                        {
                            throw new Exception("Gradient Fill was not read correctly");
                        }
 
                        settings.Angle = 0.0;
                        settings.Dither = false;
                        settings.AlignWithLayer = true;
                        settings.Reverse = true;
                        settings.HorizontalOffset = 25;
                        settings.VerticalOffset = -15;
 
                        var colorPoints = new List(settings.ColorPoints);
                        var transparencyPoints = new List(settings.TransparencyPoints);
 
                        colorPoints.Add(new GradientColorPoint()
                        {
                            Color = Color.Violet,
                            Location = 4096,
                            MedianPointLocation = 75
                        });
 
                        colorPoints[1].Location = 3000;
 
                        transparencyPoints.Add(new GradientTransparencyPoint()
                        {
                            Opacity = 80.0,
                            Location = 4096,
                            MedianPointLocation = 25
                        });
 
                        transparencyPoints[2].Location = 3000;
 
                        settings.ColorPoints = colorPoints.ToArray();
                        settings.TransparencyPoints = transparencyPoints.ToArray();
                        fillLayer.Update();
 
                        im.Save(outputFile, new PsdOptions(im));
 
                        break;
                    }
                }
            }


//转换矩阵文本层旋转的渲染
      string sourceFileName = "TransformedText.psd";
      string exportPath = "TransformedTextExport.psd";
      string exportPathPng = "TransformedTextExport.png";
 
      var im = (PsdImage)Image.Load(sourceFileName);
 
      using (im)
      {
         im.Save(exportPath);
         im.Save(exportPathPng, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
      }

-- 未完待续 --


*想要购买Aspose.Imaging正版授权的朋友可咨询哦~



标签:

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


为你推荐

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


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP