private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            //获取主题深色
            SolidColorBrush PrimaryHueDarkBrush = FindResource("PrimaryHueLightBrush") as SolidColorBrush;

            using (MagickImage image = new MagickImage(BitmapUtils.ConvertImageSourceToBitmap(Image_trackLogo.Source)))
            {
                image.Evaluate(Channels.Red, EvaluateOperator.Set, PrimaryHueDarkBrush.Color.R);
                image.Evaluate(Channels.Green, EvaluateOperator.Set, PrimaryHueDarkBrush.Color.G);
                image.Evaluate(Channels.Blue, EvaluateOperator.Set, PrimaryHueDarkBrush.Color.B);

                // 重新给Image控件赋值新图像
                Image_trackLogo.Source = image.ToBitmapSource();
            }

            //获取窗体句柄
            IntPtr hwnd = ((HwndSource)PresentationSource.FromVisual(this)).Handle;

            //通过视觉树,向上查找到Window
            var result = CusVisualTreeHelper.FindVisualParent <Window>(this);

            if (result.Count == 1)
            {
                _Window = result[0];
            }
        }
예제 #2
0
        public static MagickImage PerlinNoise(int width, int height)
        {
            using var noise1 = new MagickImage(MagickColors.Black, width / 160, height / 160);
            using var noise2 = new MagickImage(MagickColors.Black, width / 80, height / 80);
            using var noise3 = new MagickImage(MagickColors.Black, width / 40, height / 40);
            using var noise4 = new MagickImage(MagickColors.Black, width / 20, height / 20);
            using var noise5 = new MagickImage(MagickColors.Black, width / 10, height / 10);
            using var noise6 = new MagickImage(MagickColors.Black, width / 1, height / 1);

            noise1.AddNoise(NoiseType.Random);
            noise2.AddNoise(NoiseType.Random);
            noise3.AddNoise(NoiseType.Random);
            noise4.AddNoise(NoiseType.Random);
            noise5.AddNoise(NoiseType.Random);

            noise1.VirtualPixelMethod = VirtualPixelMethod.Tile;
            noise2.VirtualPixelMethod = VirtualPixelMethod.Tile;
            noise3.VirtualPixelMethod = VirtualPixelMethod.Tile;
            noise4.VirtualPixelMethod = VirtualPixelMethod.Tile;
            noise5.VirtualPixelMethod = VirtualPixelMethod.Tile;
            noise6.VirtualPixelMethod = VirtualPixelMethod.Tile;

            var geometry = new MagickGeometry(width, height)
            {
                FillArea = true
            };

            noise1.Evaluate(Channels.Default, EvaluateOperator.Multiply, 0.5);
            noise1.Evaluate(Channels.Default, EvaluateOperator.Add, 0.25);
            noise1.Resize(geometry);

            noise2.Evaluate(Channels.Default, EvaluateOperator.Multiply, 0.25);
            noise2.Evaluate(Channels.Default, EvaluateOperator.Add, 0.375);
            noise2.Resize(geometry);

            noise3.Evaluate(Channels.Default, EvaluateOperator.Multiply, 0.125);
            noise3.Evaluate(Channels.Default, EvaluateOperator.Add, 0.4375);
            noise3.Resize(geometry);

            noise4.Evaluate(Channels.Default, EvaluateOperator.Multiply, 0.0625);
            noise4.Evaluate(Channels.Default, EvaluateOperator.Add, 0.46875);
            noise4.Resize(geometry);

            noise5.Evaluate(Channels.Default, EvaluateOperator.Multiply, 0.03125);
            noise5.Evaluate(Channels.Default, EvaluateOperator.Add, 0.484375);
            noise5.Resize(geometry);

            noise6.Evaluate(Channels.Default, EvaluateOperator.Multiply, 0.015625);
            noise6.Evaluate(Channels.Default, EvaluateOperator.Add, 0.49921875);
            noise6.Resize(geometry);

            noise1.Composite(noise2, CompositeOperator.Plus);
            noise1.Composite(noise3, CompositeOperator.Plus);
            noise1.Composite(noise4, CompositeOperator.Plus);
            noise1.Composite(noise5, CompositeOperator.Plus);
            noise1.Composite(noise6, CompositeOperator.Plus);
            noise1.AutoLevel();

            return((MagickImage)noise1.Clone());
        }
예제 #3
0
        public override void Apply(MagickImage image)
        {
            // Adjust the shadows
            if (Shadows != 0)
            {
                using var shadows = image.ShadowMask(25);
                image.SetWriteMask(shadows);
                image.Evaluate(Channels.Default, EvaluateOperator.Add, new Percentage(Shadows));
            }

            // Adjust the midtones
            if (Midtones != 0)
            {
                using var midtones = image.MidtoneMask(25);
                image.SetWriteMask(midtones);
                image.Evaluate(Channels.Default, EvaluateOperator.Add, new Percentage(Midtones));
            }

            // Adjust the highlights
            if (Highlights != 0)
            {
                using var highlights = image.HighlightMask(25);
                image.SetWriteMask(highlights);
                image.Evaluate(Channels.Default, EvaluateOperator.Add, new Percentage(Highlights));
            }

            // Remove the mask
            image.RemoveWriteMask();
        }
예제 #4
0
 public override void Apply(MagickImage image)
 {
     if (Warm != 0)
     {
         image.Evaluate(Channels.Red, EvaluateOperator.Add, new Percentage(Warm));
     }
     if (Cool != 0)
     {
         image.Evaluate(Channels.Blue, EvaluateOperator.Add, new Percentage(Cool));
     }
 }
        /// <summary>
        /// 界面加载时,赋予图片主题色
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //获取主题深色
            SolidColorBrush PrimaryHueDarkBrush = FindResource("PrimaryHueDarkBrush") as SolidColorBrush;

            using (MagickImage image = new MagickImage(BitmapUtils.ConvertImageSourceToBitmap(image_Logo.Source)))
            {
                image.Evaluate(Channels.Red, EvaluateOperator.Set, PrimaryHueDarkBrush.Color.R);
                image.Evaluate(Channels.Green, EvaluateOperator.Set, PrimaryHueDarkBrush.Color.G);
                image.Evaluate(Channels.Blue, EvaluateOperator.Set, PrimaryHueDarkBrush.Color.B);

                // 重新给Image控件赋值新图像
                image_Logo.Source = image.ToBitmapSource();
            }
        }
예제 #6
0
        byte[] PhotoProcessing(string path)
        {
            if (!(File.Exists(path)))
            {
                return(null);
            }

            var img = new MagickImage(path);

            img.Quality = 90;

            //if (img.Height > img.Width)
            //    img.Resize(600, 800);
            //else
            //    img.Resize(800, 600);

            img.Interlace = Interlace.Plane;
            img.Format    = MagickFormat.Jpg;

            var watermark = new MagickImage(@"img\signature.png");

            watermark.Evaluate(Channels.Alpha, EvaluateOperator.Divide, 2);
            img.Composite(watermark, Gravity.Southwest, CompositeOperator.Over);

            return(img.ToByteArray());
        }
예제 #7
0
        /// <summary>
        /// Adds image watermark over image.
        /// </summary>
        /// <param name="srcImagePath"></param>
        public static void SaveWaterMarkedImage(string srcImagePath, string waterMarkedSavePath, System.Drawing.Bitmap watermark, double opacity = 4)
        {
            try
            {
                using (MagickImage image = new MagickImage(srcImagePath))
                {
                    // Read the watermark that will be put on top of the image
                    using (MagickImage imageWatermark = new MagickImage(watermark))
                    {
                        // Draw the watermark in the bottom right corner
                        image.Composite(imageWatermark, Gravity.Northeast, CompositeOperator.Over);

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

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

                    // Save the result
                    image.Write(waterMarkedSavePath);
                }
            }
            catch (MagickException e)
            {
                Logger.Error(e.ToString());
            }
        }
        private void MakeSemiTranspernt(MagickImage image)
        {
            double opacitySetting = Quantum.Max / (Quantum.Max * 0.5);

            image.Alpha(AlphaOption.Set);
            image.Evaluate(Channels.Alpha, EvaluateOperator.Min, Quantum.Max / opacitySetting);
        }
예제 #9
0
 static MagickImage Interpolate(MagickImage imageA, MagickImage imageB, double alpha)
 {
     if (alpha >= 1 || alpha <= 0)
     {
         return(null);
     }
     try
     {
         imageB.HasAlpha = true;
         imageB.Evaluate(Channels.Alpha, EvaluateOperator.Multiply, alpha);
         imageA.Composite(imageB, CompositeOperator.Over);
         MagickImage result;
         using (MemoryStream memoryStream = new MemoryStream())
         {
             imageA.Write(memoryStream, MagickFormat.Png32);
             ImageOptimizer optimizer = new ImageOptimizer();
             //optimizer.OptimalCompression = false;
             memoryStream.Position = 0;
             //optimizer.LosslessCompress(memoryStream);
             //FileStream fileStream = new FileStream(destinationPath, FileMode.Create);
             //memoryStream.WriteTo(fileStream);
             result = new MagickImage(memoryStream);
         }
         return(result);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
예제 #10
0
        static Tuple <bool, string> Interpolate(MagickImage imageA, MagickImage imageB, string destinationPath, double alpha)
        {
            if (alpha >= 1 || alpha <= 0)
            {
                return(new Tuple <bool, string>(false, "Alpha value must be less than 1.0 and more than 0.0"));
            }
            try
            {
                imageB.HasAlpha = true;
                imageB.Evaluate(Channels.Alpha, EvaluateOperator.Multiply, alpha);
                imageA.Composite(imageB, CompositeOperator.Over);

                using (MemoryStream memoryStream = new MemoryStream())
                {
                    imageA.Write(memoryStream, MagickFormat.Png32);
                    ImageOptimizer optimizer = new ImageOptimizer();
                    optimizer.OptimalCompression = true;
                    memoryStream.Position        = 0;
                    optimizer.LosslessCompress(memoryStream);
                    FileStream fileStream = new FileStream(destinationPath, FileMode.Create);
                    memoryStream.WriteTo(fileStream);
                }
                //imageA.Write(destinationPath, MagickFormat.Png24);
            }
            catch (Exception ex)
            {
                return(new Tuple <bool, string>(false, ex.Message));
            }
            return(new Tuple <bool, string>(true, "Success"));
        }
예제 #11
0
        public static async Task BlendImages(string img1Path, string img2Path, string[] imgOutPaths)
        {
            try
            {
                MagickImage img1 = new MagickImage(img1Path);
                MagickImage img2 = new MagickImage(img2Path);

                int alphaFraction = (100f / (imgOutPaths.Length + 1)).RoundToInt();   // Alpha percentage per image
                int currentAlpha  = alphaFraction;

                foreach (string imgOutPath in imgOutPaths)
                {
                    string outPath = imgOutPath.Trim();

                    MagickImage img1Inst = new MagickImage(img1);
                    MagickImage img2Inst = new MagickImage(img2);

                    img2Inst.Alpha(AlphaOption.Opaque);
                    img2Inst.Evaluate(Channels.Alpha, EvaluateOperator.Set, new Percentage(currentAlpha));
                    currentAlpha += alphaFraction;

                    img1Inst.Composite(img2Inst, Gravity.Center, CompositeOperator.Over);
                    img1Inst.Format  = MagickFormat.Png24;
                    img1Inst.Quality = 10;
                    img1Inst.Write(outPath);
                    await Task.Delay(1);
                }
            }
            catch (Exception e)
            {
                Logger.Log("BlendImages Error: " + e.Message);
            }
        }
예제 #12
0
        /// <summary>
        /// 满屏水印
        /// </summary>
        /// <param name="imgPath"></param>
        /// <param name="waterImgPath"></param>
        /// <returns></returns>
        public ActionResult New(string imgPath = @"M:/水印/3.jpg", string waterImgPath = @"M:/水印/水印图/黑色.png")
        {
            Stopwatch timer = new Stopwatch();

            timer.Start();

            string fileExt = Path.GetExtension(imgPath).ToLower();

            string path     = string.Format("{0}/{1}", "/lotFiles", DateTime.Now.ToString("yyyy-MM-dd"));
            string fileName = string.Format("{0}{1}", Guid.NewGuid().ToString("N"), fileExt);
            string sqlPath  = string.Format("{0}/{1}", path, fileName);
            string dirPath  = Request.MapPath(path);

            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }

            try
            {
                //原图
                using (var image = new MagickImage(imgPath))
                {
                    int imgWidth  = image.Width;
                    int imgHeight = image.Height;

                    //单个水印图
                    using (var waterimg = new MagickImage(waterImgPath))
                    {
                        int smallWidth  = waterimg.Width;
                        int smallHeight = waterimg.Height;

                        int x = Convert.ToInt32(Math.Ceiling(imgWidth * 1.0 / smallWidth));
                        int y = Convert.ToInt32(Math.Ceiling(imgHeight * 1.0 / smallHeight));

                        //透明度
                        waterimg.Evaluate(Channels.Alpha, EvaluateOperator.Divide, 2);
                        for (int i = 0; i < x; i++)
                        {
                            for (int j = 0; j < y; j++)
                            {
                                image.Composite(waterimg, i * smallWidth, j * smallHeight, CompositeOperator.Over);//水印
                            }
                        }
                    }
                    image.Write(Path.Combine(dirPath, fileName));
                }
            }
            catch (Exception ex)
            {
                ViewBag.Msg = ex.ToString();
            }

            timer.Stop();
            ViewBag.Img  = sqlPath;
            ViewBag.Time = timer.ElapsedMilliseconds;

            return(View("~/Views/Home/Index.cshtml"));
        }
        private void ApplyBrightness(MagickImage image)
        {
            if (Brightness == 1.0)
            {
                return;
            }

            image.Evaluate(Channels.All, EvaluateOperator.Multiply, Brightness);
        }
 public void ShouldThrowExceptionWhenArgumentsIsNull()
 {
     using (IMagickImage image = new MagickImage())
     {
         ExceptionAssert.ThrowsArgumentNullException("arguments", () =>
         {
             image.Evaluate(Channels.Red, EvaluateFunction.Arcsin, null);
         });
     }
 }
예제 #15
0
        /// <summary>
        /// <inheritdoc />
        /// </summary>
        public MagickImage AddWatermark(MagickImage srcImage, MagickImage watermarkImage, int opacity)
        {
            // Check if opacity is between 0 and 100
            Guard.Against.OutOfRange(opacity, nameof(opacity), 0, 100);

            watermarkImage.Evaluate(Channels.Alpha, EvaluateOperator.Multiply, (double)opacity / 100);
            srcImage.Composite(watermarkImage, Gravity.Southwest, CompositeOperator.Over);

            return(srcImage);
        }
예제 #16
0
 public void ShouldThrowExceptionWhenGeometryIsNull()
 {
     using (var image = new MagickImage())
     {
         Assert.Throws <ArgumentNullException>("geometry", () =>
         {
             image.Evaluate(Channels.Red, null, EvaluateOperator.Set, 0.0);
         });
     }
 }
예제 #17
0
            public void ShouldChangeTheSpecifiedChannels()
            {
                using (var image = new MagickImage(Files.Builtin.Logo))
                {
                    image.Evaluate(Channels.Red, EvaluateFunction.Arcsin, new double[] { 5.0 });

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

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

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

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

                    ColorAssert.Equal(new MagickColor("#00f"), image, 99, 195);
                    ColorAssert.Equal(new MagickColor("#90680000ffff"), image, 100, 295);
                }
            }
예제 #18
0
 public void ShouldThrowExceptionWhenArgumentsIsEmpty()
 {
     using (var image = new MagickImage())
     {
         Assert.Throws <ArgumentException>("arguments", () =>
         {
             image.Evaluate(Channels.Red, EvaluateFunction.Arcsin, new double[] { });
         });
     }
 }
예제 #19
0
 private MagickImage EnsureTextFlatLayerIsCreated()
 {
     if (_textFlatLayer == null)
     {
         var textLayer = EnsureTextLayerIsCreated();
         _textFlatLayer = new MagickImage(MagickColors.Transparent, textLayer.Width, textLayer.Height);
         _textFlatLayer.Evaluate(Channels.All, EvaluateOperator.Set, 0d);
     }
     return(_textFlatLayer);
 }
예제 #20
0
        /// <summary>
        /// 设置水印
        /// </summary>
        /// <param name="imgPaths"></param>
        /// <param name="waterImgPath"></param>
        /// <returns></returns>
        private int SetWaterMark(string[] imgPaths, string waterImgPath, string savePath)
        {
            int count = 0;

            for (int k = 0; k < imgPaths.Length; k++)
            {
                //文件名
                string fileName = Path.GetFileName(imgPaths[k]);
                try
                {
                    #region 水印
                    //原图
                    using (var image = new MagickImage(imgPaths[k]))
                    {
                        //todo:让水印图片没那么密集
                        int imgWidth  = image.Width;
                        int imgHeight = image.Height;

                        //单个水印图
                        using (var waterimg = new MagickImage(waterImgPath))
                        {
                            //要求把水印稀疏下
                            int smallWidth  = waterimg.Width * 2;
                            int smallHeight = waterimg.Height * 2;
                            //int smallWidth = waterimg.Width;
                            //int smallHeight = waterimg.Height;

                            int x = Convert.ToInt32(Math.Ceiling(imgWidth * 1.0 / smallWidth));
                            int y = Convert.ToInt32(Math.Ceiling(imgHeight * 1.0 / smallHeight));

                            //透明度(1~100,越大水印越淡)
                            waterimg.Evaluate(Channels.Alpha, EvaluateOperator.Divide, o);
                            for (int i = 0; i < x; i++)
                            {
                                for (int j = 0; j < y; j++)
                                {
                                    image.Composite(waterimg, i * smallWidth, j * smallHeight, CompositeOperator.Over);//水印
                                }
                            }
                        }
                        image.Write(string.Format(@"{0}\{1}", savePath, fileName));
                        count++;
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    lock (this)
                    {
                        File.AppendAllText("Images/dnt.log", ex.ToString());
                    }
                }
            }
            return(count);
        }
예제 #21
0
        public Result ResizeImage(string inputPath, string outputPath, MediaTypesScope type)
        {
            var size    = 0;
            var quality = 0;

            switch (type)
            {
            case MediaTypesScope.Background:
                break;

            case MediaTypesScope.Cover:
                size    = 400;
                quality = 75;
                break;

            case MediaTypesScope.Article:
                break;

            case MediaTypesScope.Museum:
                size    = 800;
                quality = 75;
                break;

            default:
                break;
            }

            try
            {
                using (var image = new MagickImage(inputPath))
                {
                    image.Resize(size, size);
                    image.Strip();
                    image.Quality = quality;

                    if (type == MediaTypesScope.Museum)
                    {
                        using (MagickImage watermark = new MagickImage(@"C:\EKE-Backup\Images\eke.gif"))
                        {
                            // Optionally make the watermark more transparent
                            watermark.Evaluate(Channels.Alpha, EvaluateOperator.Divide, 1.5);

                            // Or draw the watermark at a specific location
                            image.Composite(watermark, Gravity.Southeast, CompositeOperator.Over);
                        }
                    }
                    image.Write(outputPath);
                    return(new Result(ResultStatus.OK));
                }
            }
            catch (Exception)
            {
                return(new Result(ResultStatus.EXCEPTION));
            }
        }
예제 #22
0
            public void ShouldThrowExceptionWhenGeometryIsPercentage()
            {
                using (var image = new MagickImage())
                {
                    Assert.Throws <ArgumentException>("geometry", () =>
                    {
                        var geometry = new MagickGeometry(new Percentage(100), new Percentage(100));

                        image.Evaluate(Channels.Red, geometry, EvaluateOperator.Set, 0.0);
                    });
                }
            }
예제 #23
0
        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(MagickColors.Transparent, fixture.CanvasWidth, fixture.CanvasHeight))
            {
                foreach (DrawableElement drawableElement in fixture.DrawableElements)
                {
                    // A Shaded model without lightning is not shaded... but just we add this just be flexible
                    if (fixture.RendererConf.HasLight)
                    {
                        modelCanvas.Settings.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.Settings.FillColor = fixture.RendererConf.Color;
                    }

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

                if (fixture.RendererConf.HasShadow)
                {
                    CastShadow(
                        modelCanvas,
                        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);
            }
        }
예제 #24
0
        public static void BlendImages(string img1Path, string img2Path, string imgOutPath)
        {
            MagickImage img1 = new MagickImage(img1Path);
            MagickImage img2 = new MagickImage(img2Path);

            img2.Alpha(AlphaOption.Opaque);
            img2.Evaluate(Channels.Alpha, EvaluateOperator.Set, new Percentage(50));
            img1.Composite(img2, Gravity.Center, CompositeOperator.Over);
            img1.Format  = MagickFormat.Png24;
            img1.Quality = 10;
            img1.Write(imgOutPath);
        }
예제 #25
0
        public async Task SaveTextureMaps(string filename, string baseTextureName, double reflection, double gloss, double specular)
        {
            if (Kn5 == null)
            {
                return;
            }

            MagickImage image = null;
            await Task.Run(() => {
                Format format;
                var data = TextureReader.ToPng(DeviceContextHolder, Kn5.TexturesData[baseTextureName], true, out format);

                image = new MagickImage(data);
                image.AutoLevel(Channels.Red);
                image.AutoLevel(Channels.Green);
                image.AutoLevel(Channels.Blue);

                image.Evaluate(Channels.Red, EvaluateOperator.Multiply, specular);
                image.Evaluate(Channels.Green, EvaluateOperator.Multiply, gloss);
                image.Evaluate(Channels.Blue, EvaluateOperator.Multiply, reflection);
            });

            await SaveAndDispose(filename, image);
        }
예제 #26
0
        public override void Apply(MagickImage image)
        {
            using var shadowMask    = image.ShadowMask(25);
            using var midtoneMask   = image.MidtoneMask(25);
            using var highlightMask = image.HighlightMask(25);

            image.SetWriteMask(shadowMask);
            image.Evaluate(Channels.Cyan, EvaluateOperator.Add, new Percentage(ShadowCyan));
            image.Evaluate(Channels.Yellow, EvaluateOperator.Add, new Percentage(ShadowYellow));
            image.Evaluate(Channels.Magenta, EvaluateOperator.Add, new Percentage(ShadowMagenta));

            image.SetWriteMask(midtoneMask);
            image.Evaluate(Channels.Cyan, EvaluateOperator.Add, new Percentage(MidtoneCyan));
            image.Evaluate(Channels.Magenta, EvaluateOperator.Add, new Percentage(MidtoneMagenta));
            image.Evaluate(Channels.Yellow, EvaluateOperator.Add, new Percentage(MidtoneYellow));

            image.SetWriteMask(highlightMask);
            image.Evaluate(Channels.Cyan, EvaluateOperator.Add, new Percentage(HighlightCyan));
            image.Evaluate(Channels.Magenta, EvaluateOperator.Add, new Percentage(HighlightMagenta));
            image.Evaluate(Channels.Yellow, EvaluateOperator.Add, new Percentage(HighlightYellow));

            image.RemoveWriteMask();
        }
예제 #27
0
        private static MagickImage GetNormalsMapLayer(MagickImage textLayer)
        {
            var layer = new MagickImage(MagickColors.White, textLayer.Width, textLayer.Height);

            using (var blackText = new MagickImage(MagickColors.Black, textLayer.Width, textLayer.Height)) {
                blackText.Composite(textLayer, 0, 0, CompositeOperator.CopyAlpha);
                layer.Composite(blackText, 0, 0, CompositeOperator.Over);
            }

            layer.Resize(new Percentage(200));
            layer.Morphology(MorphologyMethod.Dilate, Kernel.Diamond, 1);
            layer.Resize(textLayer.Width, textLayer.Height);

            layer.Shade(0, 30, true, Channels.Red);
            layer.Shade(-90, 30, true, Channels.Green);
            layer.Evaluate(Channels.Blue, EvaluateOperator.Set, new Percentage(100d));

            return(layer);
        }
예제 #28
0
 static Tuple <bool, string> Interpolate(MagickImage imageA, MagickImage imageB, string destinationPath, double alpha)
 {
     if (alpha >= 1 || alpha <= 0)
     {
         return(new Tuple <bool, string>(false, "Alpha value must be less than 1.0 and more than 0.0"));
     }
     try
     {
         imageB.HasAlpha = true;
         imageB.Evaluate(Channels.Alpha, EvaluateOperator.Multiply, alpha);
         imageA.Composite(imageB, CompositeOperator.Over);
         imageA.Write(destinationPath, MagickFormat.Png24);
     }
     catch (Exception ex)
     {
         return(new Tuple <bool, string>(false, ex.Message));
     }
     return(new Tuple <bool, string>(true, "Success"));
 }
예제 #29
0
            public void ShouldUseWriteMask()
            {
                using (var image = new MagickImage(MagickColors.Black, 2, 1))
                {
                    using (var mask = new MagickImage(MagickColors.White, 2, 1))
                    {
                        using (var pixels = mask.GetPixelsUnsafe())
                        {
                            pixels.SetPixel(0, 0, new QuantumType[] { 0, 0, 0 });
                        }

                        image.SetWriteMask(mask);

                        image.Evaluate(Channels.Red, EvaluateOperator.Set, Quantum.Max);

                        ColorAssert.Equal(MagickColors.Red, image, 0, 0);
                        ColorAssert.Equal(MagickColors.Black, image, 1, 0);
                    }
                }
            }
예제 #30
0
        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");
            }
        }