当前位置: 首页>>代码示例>>C#>>正文


C# MagickImage.Evaluate方法代码示例

本文整理汇总了C#中ImageMagick.MagickImage.Evaluate方法的典型用法代码示例。如果您正苦于以下问题:C# MagickImage.Evaluate方法的具体用法?C# MagickImage.Evaluate怎么用?C# MagickImage.Evaluate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ImageMagick.MagickImage的用法示例。


在下文中一共展示了MagickImage.Evaluate方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateWatermark

    public static void CreateWatermark()
    {
      // Read image that needs a watermark
      using (MagickImage image = new MagickImage(SampleFiles.FujiFilmFinePixS1ProJpg))
      {
        // Read the watermark that will be put on top of the image
        using (MagickImage watermark = new MagickImage(SampleFiles.SnakewarePng))
        {
          // Draw the watermark in the bottom right corner
          image.Composite(watermark, Gravity.Southeast, CompositeOperator.Over);

          // Optionally make the watermark more transparent
          watermark.Evaluate(Channels.Alpha, EvaluateOperator.Divide, 4);

          // Or draw the watermark at a specific location
          image.Composite(watermark, 200, 50, CompositeOperator.Over);
        }

        // Save the result
        image.Write(SampleFiles.OutputDirectory + "FujiFilmFinePixS1Pro.watermark.jpg");
      }
    }
开发者ID:levesque,项目名称:Magick.NET,代码行数:22,代码来源:Watermark.cs

示例2: ExecuteEvaluate

 private void ExecuteEvaluate(XmlElement element, MagickImage image)
 {
   Hashtable arguments = new Hashtable();
   foreach (XmlAttribute attribute in element.Attributes)
   {
     if (attribute.Name == "channels")
       arguments["channels"] = Variables.GetValue<Channels>(attribute);
     else if (attribute.Name == "evaluateFunction")
       arguments["evaluateFunction"] = Variables.GetValue<EvaluateFunction>(attribute);
     else if (attribute.Name == "evaluateOperator")
       arguments["evaluateOperator"] = Variables.GetValue<EvaluateOperator>(attribute);
     else if (attribute.Name == "geometry")
       arguments["geometry"] = Variables.GetValue<MagickGeometry>(attribute);
     else if (attribute.Name == "percentage")
       arguments["percentage"] = Variables.GetValue<Percentage>(attribute);
     else if (attribute.Name == "value")
       arguments["value"] = Variables.GetValue<double>(attribute);
   }
   foreach (XmlElement elem in element.SelectNodes("*"))
   {
     arguments[elem.Name] = Variables.GetDoubleArray(elem);
   }
   if (OnlyContains(arguments, "channels", "evaluateFunction", "arguments"))
     image.Evaluate((Channels)arguments["channels"], (EvaluateFunction)arguments["evaluateFunction"], (Double[])arguments["arguments"]);
   else if (OnlyContains(arguments, "channels", "evaluateOperator", "percentage"))
     image.Evaluate((Channels)arguments["channels"], (EvaluateOperator)arguments["evaluateOperator"], (Percentage)arguments["percentage"]);
   else if (OnlyContains(arguments, "channels", "evaluateOperator", "value"))
     image.Evaluate((Channels)arguments["channels"], (EvaluateOperator)arguments["evaluateOperator"], (double)arguments["value"]);
   else if (OnlyContains(arguments, "channels", "geometry", "evaluateOperator", "percentage"))
     image.Evaluate((Channels)arguments["channels"], (MagickGeometry)arguments["geometry"], (EvaluateOperator)arguments["evaluateOperator"], (Percentage)arguments["percentage"]);
   else if (OnlyContains(arguments, "channels", "geometry", "evaluateOperator", "value"))
     image.Evaluate((Channels)arguments["channels"], (MagickGeometry)arguments["geometry"], (EvaluateOperator)arguments["evaluateOperator"], (double)arguments["value"]);
   else
     throw new ArgumentException("Invalid argument combination for 'evaluate', allowed combinations are: [channels, evaluateFunction, arguments] [channels, evaluateOperator, percentage] [channels, evaluateOperator, value] [channels, geometry, evaluateOperator, percentage] [channels, geometry, evaluateOperator, value]");
 }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:35,代码来源:MagickImage.cs

示例3: DrawTreeCluster

        private void DrawTreeCluster(MagickImage overlay, DrawableFixture fixture)
        {
            //MainForm.Log(string.Format("Image: {0} ({1}) ...", fixture.Name, fixture.TreeCluster.Tree), MainForm.LogLevel.notice);
            string fileName = System.IO.Path.GetFileNameWithoutExtension(fixture.TreeCluster.Tree);
            string defaultTree = "elm1";

            // Load model image
            if (!m_modelImages.ContainsKey(fileName))
            {
                string treeImageFile = string.Format("{0}\\data\\prerendered\\trees\\{1}.png", System.Windows.Forms.Application.StartupPath, fileName);
                if (System.IO.File.Exists(treeImageFile))
                {
                    MagickImage modelImage = new MagickImage(treeImageFile);
                    modelImage.Blur();
                    m_modelImages.Add(fileName, modelImage);
                }
                else
                {
                    MainForm.Log(string.Format("Can not find image for tree {0} ({1}), using default tree", fixture.TreeCluster.Tree, fixture.NifName), MainForm.LogLevel.warning);
                    m_modelImages.Add(fileName, m_modelImages[defaultTree]);
                }
            }

            if (m_modelImages.ContainsKey(fileName) && m_modelImages[fileName] != null)
            {
                // Get the width of the orginal tree shape
                NifRow tree = FixturesLoader.NifRows.Where(n => n.Filename.ToLower() == fixture.TreeCluster.Tree.ToLower()).FirstOrDefault();
                if (tree == null) return;

                System.Drawing.SizeF treeSize = tree.GetSize(0, 0);

                int dimensions = ((fixture.CanvasWidth > fixture.CanvasHeight) ? fixture.CanvasWidth : fixture.CanvasHeight) + 10;
                int extendedWidth = dimensions - fixture.CanvasWidth;
                int extendedHeight = dimensions - fixture.CanvasHeight;

                using (MagickImage treeCluster = new MagickImage(MagickColor.Transparent, dimensions, dimensions))
                {
                    double centerX = treeCluster.Width / 2d;
                    double centerY = treeCluster.Height / 2d;

                    foreach (SharpDX.Vector3 treeInstance in fixture.TreeCluster.TreeInstances)
                    {
                        using (MagickImage treeImage = m_modelImages[fileName].Clone())
                        {
                            double scaleWidthToTreeImage = treeSize.Width / treeImage.Width;
                            double scaleHeightToTreeImage = treeSize.Height / treeImage.Height;
                            int width = Convert.ToInt32(treeImage.Width * scaleWidthToTreeImage * fixture.Scale);
                            int height = Convert.ToInt32(treeImage.Height * scaleHeightToTreeImage * fixture.Scale);
                            treeImage.Resize(width, height);

                            int x = Convert.ToInt32(centerX - width / 2d - zoneConfiguration.ZoneCoordinateToMapCoordinate(treeInstance.X) * (fixture.FixtureRow.Scale / 100));
                            int y = Convert.ToInt32(centerY - height / 2d - zoneConfiguration.ZoneCoordinateToMapCoordinate(treeInstance.Y) * (fixture.FixtureRow.Scale / 100));
                            treeCluster.Composite(treeImage, x, y, CompositeOperator.SrcOver);
                        }
                    }

                    treeCluster.Rotate((360d * fixture.FixtureRow.AxisZ3D - fixture.FixtureRow.A) * -1);

                    using (MagickImage modelCanvas = new MagickImage(MagickColor.Transparent, fixture.CanvasWidth, fixture.CanvasHeight))
                    {
                        foreach (DrawableElement drawableElement in fixture.DrawableElements)
                        {
                            modelCanvas.FillColor = new MagickColor(
                                Convert.ToUInt16(128 * 256 * drawableElement.lightning),
                                Convert.ToUInt16(128 * 256 * drawableElement.lightning),
                                Convert.ToUInt16(128 * 256 * drawableElement.lightning)
                            );

                            DrawablePolygon polyDraw = new DrawablePolygon(drawableElement.coordinates);
                            modelCanvas.Draw(polyDraw);
                        }

                        modelCanvas.Composite(treeCluster, Gravity.Center, CompositeOperator.DstIn);
                        treeCluster.Composite(modelCanvas, Gravity.Center, CompositeOperator.Overlay);
                        //treeCluster.Composite(modelCanvas, Gravity.Center, CompositeOperator.SrcOver);
                    }

                    if (fixture.RendererConf.HasShadow)
                    {
                        treeCluster.BorderColor = MagickColor.Transparent;
                        treeCluster.Border(1);
                        treeCluster.Shadow(
                            fixture.RendererConf.ShadowOffsetX,
                            fixture.RendererConf.ShadowOffsetY,
                            fixture.RendererConf.ShadowSize,
                            new Percentage(100 - fixture.RendererConf.ShadowTransparency),
                            fixture.RendererConf.ShadowColor
                        );
                    }

                    if (fixture.RendererConf.Transparency != 0)
                    {
                        treeCluster.Alpha(AlphaOption.Set);

                        double divideValue = 100.0 / (100.0 - fixture.RendererConf.Transparency);
                        treeCluster.Evaluate(Channels.Alpha, EvaluateOperator.Divide, divideValue);
                    }

                    overlay.Composite(treeCluster, Convert.ToInt32(fixture.CanvasX - extendedWidth/2), Convert.ToInt32(fixture.CanvasY - extendedHeight/2), CompositeOperator.SrcOver);
                }
//.........这里部分代码省略.........
开发者ID:Merec,项目名称:DAoC-MapCreator,代码行数:101,代码来源:MapFixtures.cs

示例4: DrawTree

        private void DrawTree(MagickImage overlay, DrawableFixture fixture)
        {
            System.Drawing.Color testColor = System.Drawing.ColorTranslator.FromHtml("#5e683a");

            using (MagickImage pattern = new MagickImage(MagickColor.Transparent, fixture.CanvasWidth, fixture.CanvasHeight))
            {
                using (MagickImage patternTexture = new MagickImage(string.Format("{0}\\data\\textures\\{1}.png", System.Windows.Forms.Application.StartupPath, "leaves_mask")))
                {
                    patternTexture.Resize(fixture.CanvasWidth / 2, fixture.CanvasHeight / 2);
                    pattern.Texture(patternTexture);

                    Random rnd = new Random();
                    pattern.Rotate(rnd.Next(0, 360));

                    using (MagickImage modelCanvas = new MagickImage(MagickColor.Transparent, fixture.CanvasWidth, fixture.CanvasHeight))
                    {
                        foreach (DrawableElement drawableElement in fixture.DrawableElements)
                        {
                            DrawablePolygon polyDraw = new DrawablePolygon(drawableElement.coordinates);

                            // A Shaded model without lightning is not shaded... but just we add this just be flexible
                            if (fixture.RendererConf.HasLight)
                            {
                                float r, g, b, light;

                                light = (float)drawableElement.lightning * 2f;
                                r = fixture.Tree.AverageColor.R * light;
                                g = fixture.Tree.AverageColor.G * light;
                                b = fixture.Tree.AverageColor.B * light;

                                modelCanvas.FillColor = new MagickColor(
                                    Convert.ToUInt16(r * 255),
                                    Convert.ToUInt16(g * 255),
                                    Convert.ToUInt16(b * 255)
                                );
                            }
                            else
                            {
                                modelCanvas.FillColor = fixture.RendererConf.Color;
                            }

                            modelCanvas.Draw(polyDraw);
                        }

                        // Add leaves pattern
                        pattern.Composite(modelCanvas, Gravity.Center, CompositeOperator.DstIn);
                        modelCanvas.Composite(pattern, Gravity.Center, CompositeOperator.CopyAlpha);

                        if (fixture.RendererConf.HasShadow)
                        {
                            modelCanvas.BorderColor = MagickColor.Transparent;
                            modelCanvas.Border((int)fixture.RendererConf.ShadowSize);
                            modelCanvas.Shadow(
                                fixture.RendererConf.ShadowOffsetX,
                                fixture.RendererConf.ShadowOffsetY,
                                fixture.RendererConf.ShadowSize,
                                new Percentage(100 - fixture.RendererConf.ShadowTransparency),
                                fixture.RendererConf.ShadowColor
                            );

                            // Update the canvas position to match the new border
                            fixture.CanvasX -= fixture.RendererConf.ShadowSize;
                            fixture.CanvasY -= fixture.RendererConf.ShadowSize;
                        }

                        if (fixture.RendererConf.Transparency != 0)
                        {
                            modelCanvas.Alpha(AlphaOption.Set);

                            double divideValue = 100.0 / (100.0 - fixture.RendererConf.Transparency);
                            modelCanvas.Evaluate(Channels.Alpha, EvaluateOperator.Divide, divideValue);
                        }

                        overlay.Composite(modelCanvas, Convert.ToInt32(fixture.CanvasX), Convert.ToInt32(fixture.CanvasY), CompositeOperator.SrcOver);
                    }
                }
            }
        }
开发者ID:Merec,项目名称:DAoC-MapCreator,代码行数:78,代码来源:MapFixtures.cs

示例5: DrawShaded

        private void DrawShaded(MagickImage overlay, DrawableFixture fixture)
        {
            //MainForm.Log(string.Format("Shaded: {0} ({1}) ...", fixture.Name, fixture.NifName), MainForm.LogLevel.notice);

            using (MagickImage modelCanvas = new MagickImage(MagickColor.Transparent, fixture.CanvasWidth, fixture.CanvasHeight))
            {
                foreach (DrawableElement drawableElement in fixture.DrawableElements)
                {
                    DrawablePolygon polyDraw = new DrawablePolygon(drawableElement.coordinates);

                    // A Shaded model without lightning is not shaded... but just we add this just be flexible
                    if (fixture.RendererConf.HasLight)
                    {
                        modelCanvas.FillColor = new MagickColor(
                            Convert.ToUInt16(drawableElement.lightning * fixture.RendererConf.Color.R),
                            Convert.ToUInt16(drawableElement.lightning * fixture.RendererConf.Color.G),
                            Convert.ToUInt16(drawableElement.lightning * fixture.RendererConf.Color.B)
                        );
                    }
                    else
                    {
                        modelCanvas.FillColor = fixture.RendererConf.Color;
                    }

                    modelCanvas.Draw(polyDraw);

                }

                if (fixture.RendererConf.HasShadow)
                {
                    modelCanvas.BorderColor = MagickColor.Transparent;
                    modelCanvas.Border((int)fixture.RendererConf.ShadowSize);
                    modelCanvas.Shadow(
                        fixture.RendererConf.ShadowOffsetX,
                        fixture.RendererConf.ShadowOffsetY,
                        fixture.RendererConf.ShadowSize,
                        new Percentage(100 - fixture.RendererConf.ShadowTransparency),
                        fixture.RendererConf.ShadowColor
                    );

                    // Update the canvas position to match the new border
                    fixture.CanvasX -= fixture.RendererConf.ShadowSize;
                    fixture.CanvasY -= fixture.RendererConf.ShadowSize;
                }

                if (fixture.RendererConf.Transparency != 0)
                {
                    modelCanvas.Alpha(AlphaOption.Set);

                    double divideValue = 100.0 / (100.0 - fixture.RendererConf.Transparency);
                    modelCanvas.Evaluate(Channels.Alpha, EvaluateOperator.Divide, divideValue);
                }

                overlay.Composite(modelCanvas, Convert.ToInt32(fixture.CanvasX), Convert.ToInt32(fixture.CanvasY), CompositeOperator.SrcOver);
            }
        }
开发者ID:Merec,项目名称:DAoC-MapCreator,代码行数:56,代码来源:MapFixtures.cs

示例6: DrawImage


//.........这里部分代码省略.........
                    else m_modelImages.Add(fileName, null);
                }
            }

            // Draw the image
            if (m_modelImages.ContainsKey(fileName) && m_modelImages[fileName] != null)
            {
                NifRow orginalNif = FixturesLoader.NifRows.Where(n => n.NifId == fixture.FixtureRow.NifId).FirstOrDefault();
                if (orginalNif == null)
                {
                    MainForm.Log(string.Format("Error with imaged nif ({0})!", fixture.FixtureRow.TextualName), MainForm.LogLevel.warning);
                }

                System.Drawing.SizeF objectSize = orginalNif.GetSize(0, 0);

                // The final image
                using (MagickImage modelImage = new MagickImage(MagickColor.Transparent, fixture.CanvasWidth, fixture.CanvasHeight))
                {
                    // Place the replacing image
                    using (MagickImage newModelImage = m_modelImages[fileName].Clone())
                    {
                        newModelImage.BackgroundColor = MagickColor.Transparent;

                        double scaleWidthToTreeImage = objectSize.Width / newModelImage.Width;
                        double scaleHeightToTreeImage = objectSize.Height / newModelImage.Height;
                        int width = Convert.ToInt32(newModelImage.Width * scaleWidthToTreeImage * fixture.Scale);
                        int height = Convert.ToInt32(newModelImage.Height * scaleHeightToTreeImage * fixture.Scale);

                        // Resize to new size
                        newModelImage.FilterType = FilterType.Gaussian;
                        newModelImage.VirtualPixelMethod = VirtualPixelMethod.Transparent;
                        newModelImage.Resize(width, height);

                        // Rotate the image
                        //newModelImage.Rotate(fixture.FixtureRow.A * -1 * fixture.FixtureRow.AxisZ3D);
                        newModelImage.Rotate((360d * fixture.FixtureRow.AxisZ3D - fixture.FixtureRow.A) * -1);

                        // Place in center of modelImage
                        modelImage.Composite(newModelImage, Gravity.Center, CompositeOperator.SrcOver);
                    }

                    // Draw the shaped model if wanted
                    if (fixture.RendererConf.HasLight)
                    {
                        using (MagickImage modelShaped = new MagickImage(MagickColor.Transparent, fixture.CanvasWidth, fixture.CanvasHeight))
                        {
                            foreach (DrawableElement drawableElement in fixture.DrawableElements)
                            {
                                var light = 1 - drawableElement.lightning;
                                modelShaped.FillColor = new MagickColor(
                                    Convert.ToUInt16(ushort.MaxValue * light),
                                    Convert.ToUInt16(ushort.MaxValue * light),
                                    Convert.ToUInt16(ushort.MaxValue * light)
                                );

                                DrawablePolygon polyDraw = new DrawablePolygon(drawableElement.coordinates);
                                modelShaped.Draw(polyDraw);
                            }

                            using(MagickImage modelMask = new MagickImage(MagickColor.Transparent, fixture.CanvasWidth, fixture.CanvasHeight))
                            {
                                modelShaped.Blur();
                                modelMask.Composite(modelShaped, 0, 0, CompositeOperator.DstAtop);
                                modelMask.Composite(modelImage, 0, 0, CompositeOperator.DstIn);
                                modelMask.Level(new Percentage(20), new Percentage(100), Channels.All);
                                modelImage.Composite(modelMask, 0, 0, CompositeOperator.ColorDodge);
                            }
                        }
                    }

                    // Add the shadow if not a tree (tree shadow are substituted by a treeoverlay)
                    if (fixture.RendererConf.HasShadow && !fixture.IsTree)
                    {
                        modelImage.BorderColor = MagickColor.Transparent;
                        modelImage.Border((int)fixture.RendererConf.ShadowSize);
                        modelImage.Shadow(
                            fixture.RendererConf.ShadowOffsetX,
                            fixture.RendererConf.ShadowOffsetY,
                            fixture.RendererConf.ShadowSize,
                            new Percentage(100 - fixture.RendererConf.ShadowTransparency),
                            fixture.RendererConf.ShadowColor
                        );

                        // Update the canvas position to match the new border
                        fixture.CanvasX -= fixture.RendererConf.ShadowSize;
                        fixture.CanvasY -= fixture.RendererConf.ShadowSize;
                    }

                    // Set transprency if not a tree (see shadow)
                    if (fixture.RendererConf.Transparency != 0 && !fixture.IsTree)
                    {
                        double divideValue = 100.0 / (100.0 - fixture.RendererConf.Transparency);
                        modelImage.Evaluate(Channels.Alpha, EvaluateOperator.Divide, divideValue);
                    }

                    // Place the image on the right position
                    overlay.Composite(modelImage, Convert.ToInt32(fixture.CanvasX), Convert.ToInt32(fixture.CanvasY), CompositeOperator.SrcOver);
                }
            }
        }
开发者ID:Merec,项目名称:DAoC-MapCreator,代码行数:101,代码来源:MapFixtures.cs

示例7: Draw

        private void Draw(MagickImage map, List<DrawableFixture> fixtures)
        {
            MainForm.ProgressStart(string.Format("Drawing fixtures ({0}) ...", fixtures.Count));
            Stopwatch timer = Stopwatch.StartNew();

            using (MagickImage modelsOverlay = new MagickImage(MagickColor.Transparent, zoneConfiguration.TargetMapSize, zoneConfiguration.TargetMapSize))
            {
                using (MagickImage treeOverlay = new MagickImage(MagickColor.Transparent, zoneConfiguration.TargetMapSize, zoneConfiguration.TargetMapSize))
                {
                    int processCounter = 0;
                    foreach (DrawableFixture fixture in fixtures)
                    {
                        // Debug single models
                        /*
                        if (fixture.FixtureRow.NifId != 443 && fixture.FixtureRow.NifId != 433 && fixture.FixtureRow.NifId != 459)
                        {
                            continue;
                        }
                        else
                        {
                            DrawShaded((fixture.IsTree || fixture.IsTreeCluster) ? treeOverlay : modelsOverlay, fixture);
                        }
                        */

                        switch (fixture.RendererConf.Renderer)
                        {
                            case FixtureRenderererType.Shaded:
                                DrawShaded((fixture.IsTree || fixture.IsTreeCluster) ? treeOverlay : modelsOverlay, fixture);
                                break;
                            case FixtureRenderererType.Flat:
                                DrawFlat((fixture.IsTree || fixture.IsTreeCluster) ? treeOverlay : modelsOverlay, fixture);
                                break;
                            case FixtureRenderererType.Image:
                                //DrawShaded((fixture.IsTree || fixture.IsTreeCluster) ? treeOverlay : modelsOverlay, fixture);
                                DrawImage((fixture.IsTree || fixture.IsTreeCluster) ? treeOverlay : modelsOverlay, fixture);
                                break;
                        }

                        int percent = 100 * processCounter / fixtures.Count();
                        MainForm.ProgressUpdate(percent);
                        processCounter++;
                    }

                    MainForm.ProgressStartMarquee("Merging ...");

                    FixtureRendererConfiguration2 treeImagesRConf = FixtureRendererConfigurations.GetRendererById("TreeImage");
                    if (treeImagesRConf.HasShadow)
                    {
                        //treeOverlay.BorderColor = MagickColor.Transparent;
                        //treeOverlay.Border(1);
                        treeOverlay.Shadow(
                            treeImagesRConf.ShadowOffsetX,
                            treeImagesRConf.ShadowOffsetY,
                            treeImagesRConf.ShadowSize,
                            new Percentage(100 - treeImagesRConf.ShadowTransparency),
                            treeImagesRConf.ShadowColor
                        );

                    }

                    if (treeImagesRConf.Transparency != 0)
                    {
                        treeOverlay.Alpha(AlphaOption.Set);
                        double divideValue = 100.0 / (100.0 - TreeTransparency);
                        treeOverlay.Evaluate(Channels.Alpha, EvaluateOperator.Divide, divideValue);
                    }

                    map.Composite(modelsOverlay, 0, 0, CompositeOperator.SrcOver);
                    map.Composite(treeOverlay, 0, 0, CompositeOperator.SrcOver);
                }
            }

            timer.Stop();
            MainForm.Log(string.Format("Finished in {0} seconds.", timer.Elapsed.TotalSeconds), MainForm.LogLevel.success);
            MainForm.ProgressReset();
        }
开发者ID:Merec,项目名称:DAoC-MapCreator,代码行数:76,代码来源:MapFixtures.cs

示例8: Draw

        /// <summary>
        /// Draw the bounds onto map
        /// </summary>
        /// <param name="map"></param>
        public void Draw(MagickImage map)
        {
            if (m_bounds.Count == 0) return;
            MainForm.ProgressStart("Drawing zone bounds ...");

            // Sort the polygons
            List<List<Coordinate>> polygons = new List<List<Coordinate>>();
            List<List<Coordinate>> negatedPolygons = new List<List<Coordinate>>();

            foreach (List<PointF> polygon in m_bounds)
            {
                bool isClockwise = Tools.PolygonHasClockwiseOrder(polygon);
                var polygonConverted = polygon.Select(c => new Coordinate(zoneConfiguration.ZoneCoordinateToMapCoordinate(c.X), zoneConfiguration.ZoneCoordinateToMapCoordinate(c.Y))).ToList();

                // polygons in clockwise order needs to be negated
                if (isClockwise) negatedPolygons.Add(polygonConverted);
                else polygons.Add(polygonConverted);
            }

            MagickColor backgroundColor = MagickColor.Transparent;
            if (polygons.Count == 0) {
                // There are no normal polygons, we need to fill the hole zone and substract negatedPolygons
                backgroundColor = m_boundsColor;
            }

            using (MagickImage boundMap = new MagickImage(backgroundColor, zoneConfiguration.TargetMapSize, zoneConfiguration.TargetMapSize))
            {
                int progressCounter = 0;

                boundMap.Alpha(AlphaOption.Set);
                boundMap.FillColor = m_boundsColor;
                foreach (List<Coordinate> coords in polygons)
                {
                    DrawablePolygon poly = new DrawablePolygon(coords);
                    boundMap.Draw(poly);

                    progressCounter++;
                    int percent = 100 * progressCounter / m_bounds.Count();
                    MainForm.ProgressUpdate(percent);
                }

                if (negatedPolygons.Count > 0)
                {
                    using (MagickImage negatedBoundMap = new MagickImage(Color.Transparent, zoneConfiguration.TargetMapSize, zoneConfiguration.TargetMapSize))
                    {
                        negatedBoundMap.FillColor = m_boundsColor;

                        foreach (List<Coordinate> coords in negatedPolygons)
                        {
                            DrawablePolygon poly = new DrawablePolygon(coords);
                            negatedBoundMap.Draw(poly);

                            progressCounter++;
                            int percent = 100 * progressCounter / m_bounds.Count();
                            MainForm.ProgressUpdate(percent);
                        }
                        boundMap.Composite(negatedBoundMap, 0, 0, CompositeOperator.DstOut);
                    }
                }

                MainForm.ProgressStartMarquee("Merging ...");
                if (ExcludeFromMap)
                {
                    map.Composite(boundMap, 0, 0, CompositeOperator.DstOut);
                }
                else
                {
                    if (m_transparency != 0)
                    {
                        boundMap.Alpha(AlphaOption.Set);
                        double divideValue = 100.0 / (100.0 - m_transparency);
                        boundMap.Evaluate(Channels.Alpha, EvaluateOperator.Divide, divideValue);
                    }

                    map.Composite(boundMap, 0, 0, CompositeOperator.SrcOver);
                }
            }

            if (debug)
            {
                DebugMaps();
            }

            MainForm.ProgressReset();
        }
开发者ID:Merec,项目名称:DAoC-MapCreator,代码行数:89,代码来源:MapBounds.cs

示例9: Draw

        public void Draw(MagickImage map)
        {
            MainForm.ProgressStart("Rendering water ...");

            using (PixelCollection heightmapPixels = zoneConfiguration.Heightmap.HeightmapScaled.GetReadOnlyPixels())
            {
                using (MagickImage water = new MagickImage(MagickColor.Transparent, zoneConfiguration.TargetMapSize, zoneConfiguration.TargetMapSize))
                {
                    int progressCounter = 0;

                    foreach (WaterConfiguration river in m_waterAreas)
                    {
                        MainForm.Log(river.Name + "...", MainForm.LogLevel.notice);

                        MagickColor fillColor;
                        if (m_useClientColors) fillColor = river.Color;
                        else fillColor = m_waterColor;
                        //water.FillColor = fillColor;

                        // Get the river coordinates and scale them to the targets size
                        List<Coordinate> riverCoordinates = river.GetCoordinates().Select(c => new Coordinate(c.X * zoneConfiguration.MapScale, c.Y * zoneConfiguration.MapScale)).ToList();

                        // Texture
                        using (MagickImage texture = new MagickImage((river.Type.ToLower() == "lava") ? GetLavaTexture() : GetWateryTexture()))
                        {
                            using (MagickImage pattern = new MagickImage(fillColor, texture.Width, texture.Height))
                            {
                                texture.Composite(pattern, 0, 0, CompositeOperator.DstIn);
                                texture.Composite(pattern, 0, 0, CompositeOperator.ColorDodge);

                                water.FillPattern = texture;
                                DrawablePolygon poly = new DrawablePolygon(riverCoordinates);
                                water.Draw(poly);
                            }
                        }

                        // get the min/max and just process them
                        int minX = Convert.ToInt32(riverCoordinates.Min(m => m.X)) - 10;
                        int maxX = Convert.ToInt32(riverCoordinates.Max(m => m.X)) + 10;
                        int minY = Convert.ToInt32(riverCoordinates.Min(m => m.Y)) - 10;
                        int maxY = Convert.ToInt32(riverCoordinates.Max(m => m.Y)) + 10;

                        using (WritablePixelCollection riverPixelCollection = water.GetWritablePixels())
                        {
                            for (int x = minX; x < maxX; x++)
                            {
                                if (x < 0) continue;
                                if (x >= zoneConfiguration.TargetMapSize) continue;

                                for (int y = minY; y < maxY; y++)
                                {
                                    if (y < 0) continue;
                                    if (y >= zoneConfiguration.TargetMapSize) continue;

                                    ushort pixelHeight = heightmapPixels.GetPixel(x, y).GetChannel(0);
                                    if (pixelHeight > river.Height)
                                    {
                                        Pixel newPixel = new Pixel(x, y, new ushort[] { 0, 0, 0, ushort.MinValue });
                                        riverPixelCollection.Set(newPixel);
                                    }
                                }
                            }
                        }

                        if (debug)
                        {
                            DebugRiver(progressCounter, river, riverCoordinates);
                        }

                        int percent = 100 * progressCounter / m_waterAreas.Count();
                        MainForm.ProgressUpdate(percent);
                        progressCounter++;
                    }

                    MainForm.ProgressStartMarquee("Merging...");

                    if (WaterTransparency != 0)
                    {
                        water.Alpha(AlphaOption.Set);
                        double divideValue = 100.0 / (100.0 - WaterTransparency);
                        water.Evaluate(Channels.Alpha, EvaluateOperator.Divide, divideValue);
                    }

                    water.Blur();
                    map.Composite(water, 0, 0, CompositeOperator.SrcOver);
                }
            }

            MainForm.ProgressReset();
        }
开发者ID:Merec,项目名称:DAoC-MapCreator,代码行数:90,代码来源:MapWater.cs

示例10: Test_Evaluate

    public void Test_Evaluate()
    {
      using (MagickImage image = new MagickImage(Files.Builtin.Logo))
      {
        ExceptionAssert.Throws<ArgumentNullException>(delegate ()
        {
          image.Evaluate(Channels.Red, EvaluateFunction.Arcsin, null);
        });

        ExceptionAssert.Throws<ArgumentException>(delegate ()
        {
          image.Evaluate(Channels.Red, EvaluateFunction.Arcsin, new double[] { });
        });

        ExceptionAssert.Throws<ArgumentNullException>(delegate ()
        {
          image.Evaluate(Channels.Red, null, EvaluateOperator.Set, 0.0);
        });

        image.Evaluate(Channels.Red, EvaluateFunction.Arcsin, new double[] { 5.0 });

        ColorAssert.AreEqual(new MagickColor("#9068ffffffff"), image, 100, 295);

        image.Evaluate(Channels.Red, new MagickGeometry(0, 0, 100, 295), EvaluateOperator.Set, 0);

        ColorAssert.AreEqual(new MagickColor("#0ff"), image, 99, 195);
        ColorAssert.AreEqual(new MagickColor("#9068ffffffff"), image, 100, 295);

        image.Evaluate(Channels.Green, EvaluateOperator.Set, 0);

        ColorAssert.AreEqual(new MagickColor("#00f"), image, 99, 195);
        ColorAssert.AreEqual(new MagickColor("#90680000ffff"), image, 100, 295);
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:34,代码来源:MagickImageTests.cs

示例11: ExecuteThread

        public string ExecuteThread(FileItem item, string infile, string dest, ValuePairEnumerator configData)
        {
            var conf = new OverlayTransformViewModel(configData);
            using (MagickImage image = new MagickImage(infile))
            {
                Gravity gravity = Gravity.Center;
                if (conf.A11)
                {
                    gravity = Gravity.Northwest;
                }
                if (conf.A12)
                {
                    gravity = Gravity.North;
                }
                if (conf.A13)
                {
                    gravity = Gravity.Northeast;
                }
                if (conf.A21)
                {
                    gravity = Gravity.West;
                }
                if (conf.A22)
                {
                    gravity = Gravity.Center;
                }
                if (conf.A23)
                {
                    gravity = Gravity.East;
                }
                if (conf.A31)
                {
                    gravity = Gravity.Southwest;
                }
                if (conf.A32)
                {
                    gravity = Gravity.South;
                }
                if (conf.A33)
                {
                    gravity = Gravity.Southeast;
                }


                if (File.Exists(conf.OverlayFile))
                {
                    // Read the watermark that will be put on top of the image
                    using (MagickImage watermark = new MagickImage(conf.OverlayFile))
                    {
                        if (conf.StrechOverlay)
                            watermark.Resize(image.Width, image.Height);
                        // Optionally make the watermark more transparent
                        if (conf.Transparency != 100)
                            watermark.Evaluate(Channels.Alpha, EvaluateOperator.Add,
                                -(255*(100 - conf.Transparency)/100));
                        // Draw the watermark in the bottom right corner
                        image.Composite(watermark, gravity, CompositeOperator.Over);

                        //// Optionally make the watermark more transparent
                        //watermark.Evaluate(Channels.Alpha, EvaluateOperator.Divide, 4);

                        //// Or draw the watermark at a specific location
                        //image.Composite(watermark, 200, 50, CompositeOperator.Over);
                    }
                }

                string text = "";
                if (!string.IsNullOrEmpty(conf.Text))
                {
                    Regex regPattern = new Regex(@"\[(.*?)\]", RegexOptions.Singleline);
                    MatchCollection matchX = regPattern.Matches(conf.Text);
                    text = matchX.Cast<Match>()
                        .Aggregate(conf.Text,
                            (current1, match) =>
                                item.FileNameTemplates.Where(
                                    template =>
                                        String.Compare(template.Name, match.Value,
                                            StringComparison.InvariantCultureIgnoreCase) == 0).Aggregate(current1,
                                                (current, template) => current.Replace(match.Value, template.Value)));

                    image.Font = conf.Font;
                    image.FontPointsize = conf.FontSize;
                    Color color = (Color) ColorConverter.ConvertFromString(conf.FontColor);
                    image.FillColor = new MagickColor(color.R, color.G, color.B, color.A);
                    image.StrokeColor = new MagickColor(color.R, color.G, color.B, color.A);
                    image.Annotate(text, gravity);
                }
                image.Format = MagickFormat.Jpeg;
                image.Write(dest);
            }
            return dest;
        }
开发者ID:avencherus,项目名称:digiCamControl,代码行数:92,代码来源:OverlayTransform.cs


注:本文中的ImageMagick.MagickImage.Evaluate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。