コード例 #1
0
 private static double GetRatio(IMagickImage image, Channels channel, IMagickImage mask, double maskMean)
 {
     using (IMagickImage channelImage = image.Separate(channel).First())
     {
         channelImage.Composite(mask, CompositeOperator.Multiply);
         var channelMean = GetMean(channelImage);
         var average     = 100 * channelMean / maskMean;
         return(100 / average);
     }
 }
コード例 #2
0
        /// <summary>
        ///     Performs a circular crop on an image.
        /// </summary>
        /// <param name="image">The image to crop.</param>
        internal static void CircularCrop(IMagickImage image)
        {
            using var copy = image.Clone();
            copy.Distort(DistortMethod.DePolar, 0);
            copy.VirtualPixelMethod = VirtualPixelMethod.HorizontalTile;
            copy.BackgroundColor    = MagickColors.None;
            copy.Distort(DistortMethod.Polar, 0);

            image.Composite(copy, CompositeOperator.CopyAlpha);
        }
コード例 #3
0
        static public void RoundImage(this IMagickImage <byte> image)
        {
            using var mask = new MagickImage(MagickColors.Transparent, image.Width, image.Height);
            new Drawables()
            .FillColor(MagickColors.White)
            .Circle(image.Width / 2, image.Height / 2, image.Width / 2, 0)
            .Draw(mask);

            image.Alpha(AlphaOption.On);
            image.Composite(mask, CompositeOperator.Multiply);
        }
コード例 #4
0
        public void CastShadow(IMagickImage caster, int offsetX, int offsetY, double size, Percentage alpha, MagickColor color, bool extendCasterWithBorder = true)
        {
            using (IMagickImage shadow = caster.Clone())
            {
                shadow.Shadow(offsetX, offsetY, size, alpha, color);

                if (extendCasterWithBorder)
                {
                    caster.BorderColor = MagickColors.Transparent;
                    caster.Border((int)size);
                }

                caster.Composite(shadow, 0, 0, CompositeOperator.DstOver);
            }
        }
コード例 #5
0
ファイル: AImage.cs プロジェクト: ogoun/darkset
 public void BlurBoxes(BBOXES boxes)
 {
     foreach (var rect in boxes.ToMagikGeometry())
     {
         if (rect.X >= 0 && rect.Y >= 0 && rect.Width > 0 && rect.Height > 0)
         {
             using (var crop_clone = new MagickImage(_current.ToByteArray()))
             {
                 crop_clone.Crop(rect);
                 crop_clone.Blur();
                 _current.Composite(crop_clone, rect.X, rect.Y, CompositeOperator.Over);
             }
         }
     }
 }
コード例 #6
0
        public Stream Compare()
        {
            IMagickImage modifiedHigh = ReadPDF(_modifiedImagePath, _magickSettingsHigh);
            IMagickImage original     = ReadPDF(_originalImagePath, _magickSettings);
            IMagickImage modified     = ReadPDF(_modifiedImagePath, _magickSettings);

            IMagickImage mask = GenerateMask(original, modified);

            mask.Resize(new Percentage((double)Density / (double)ReducedDensity * 100d));
            modifiedHigh.Composite(mask, Gravity.Center, CompositeOperator.Over);

            MemoryStream ms = new MemoryStream();

            modifiedHigh.Write(ms);
            ms.Position = 0;

            return(ms);
        }
コード例 #7
0
        private void AddBevel(IMagickImage image)
        {
            using (var alphaTexture = image.Clone())
            {
                alphaTexture.Alpha(AlphaOption.Extract);
                alphaTexture.Blur(0, Bevel);
                alphaTexture.Shade(Azimuth, Elevation);
                alphaTexture.Composite(image, CompositeOperator.CopyAlpha);
                alphaTexture.Alpha(AlphaOption.On);
                alphaTexture.Alpha(AlphaOption.Background);
                alphaTexture.Alpha(AlphaOption.Deactivate);
                alphaTexture.AutoLevel(Channels.Composite);
                alphaTexture.Evaluate(Channels.Composite, EvaluateFunction.Polynomial, new double[] { 3.5, -5.05, 2.05, 0.25 });
                alphaTexture.SigmoidalContrast(Contrast);
                alphaTexture.Alpha(AlphaOption.On);

                image.Composite(alphaTexture, CompositeOperator.HardLight);
            }
        }
コード例 #8
0
        public IMagickImage Execute(IMagickImage image, ValueItemCollection values)
        {
            Variables = values;
            if (RemoveBackgroundActive)
            {
                image.ColorAlpha(MagickColors.Transparent);

                image.Alpha(AlphaOption.Set);
                image.VirtualPixelMethod = VirtualPixelMethod.Transparent;

                //                image.ColorFuzz = new Percentage(RemoveBackgroundThreshold);
                //                image.TransparentChroma(new MagickColor("#FFFFFF"), new MagickColor("#F0F0F0"));
                //                image.Transparent(MagickColor.FromRgb(255, 255, 255));


                var clone = image.Clone();
                clone.ColorFuzz = new Percentage(RemoveBackgroundThreshold);
                clone.TransparentChroma(new MagickColor("#FFFFFF"), new MagickColor("#F0F0F0"));
                clone.Transparent(MagickColor.FromRgb(255, 255, 255));


                if (RemoveBackgroundFeather > 0)
                {
                    clone.Scale(new Percentage(10));
                    clone.Blur(0, RemoveBackgroundFeather, Channels.Alpha);
                    clone.Resize(image.Width, image.Width);
                }
                image.Composite(clone, CompositeOperator.CopyAlpha);

                image.Alpha(AlphaOption.Background);
                using (MagickImageCollection images = new MagickImageCollection())
                {
                    var back = new MagickImage(MagickColors.White, image.Width, image.Height);
                    images.Add(back);
                    images.Add(image);
                    image = images.Flatten().Clone();
                }
            }
            //            image.Threshold(new Percentage(RemoveBackgroundThreshold));

            //            image.Transparent(MagickColor.FromRgb(255, 255, 255));
            return(image);
        }
        private void RemoveNoise(IMagickImage image)
        {
            using (var second = image.Clone())
            {
                second.ColorSpace = ColorSpace.Gray;
                second.Negate();
                second.AdaptiveThreshold(FilterSize, FilterSize, FilterOffset);
                second.ContrastStretch((Percentage)0);

                if (SmoothingThreshold != null)
                {
                    second.Blur(SmoothingThreshold.Value.ToDouble() / 100, Quantum.Max);
                    second.Level(SmoothingThreshold.Value, new Percentage(100));
                }

                image.Composite(second, CompositeOperator.CopyAlpha);
            }

            image.Opaque(MagickColors.Transparent, BackgroundColor);
            image.Alpha(AlphaOption.Off);
        }
コード例 #10
0
        private void CopyOpacity(IMagickImage image)
        {
            image.Alpha(AlphaOption.Off);

            using (var gray = image.Clone())
            {
                gray.ColorSpace = ColorSpace.Gray;
                gray.Negate();
                gray.AdaptiveThreshold(FilterSize, FilterSize, FilterOffset);
                gray.ContrastStretch((Percentage)0);
                if (Threshold.HasValue)
                {
                    gray.Blur((double)Threshold.Value / 100.0, Quantum.Max);
                    gray.Level(Threshold.Value, new Percentage(100));
                }

                image.Composite(gray, CompositeOperator.CopyAlpha);
                image.Opaque(MagickColors.Transparent, BackgroundColor);
                image.Alpha(AlphaOption.Off);
            }
        }
コード例 #11
0
                public void ShouldCopyTheAlphaChannelWithCopyAlpha()
                {
                    var readSettings = new MagickReadSettings()
                    {
                        BackgroundColor = MagickColors.None,
                        FillColor       = MagickColors.White,
                        FontPointsize   = 100,
                    };

                    using (IMagickImage image = new MagickImage("label:Test", readSettings))
                    {
                        using (IMagickImage alpha = image.Clone())
                        {
                            alpha.Alpha(AlphaOption.Extract);
                            alpha.Shade(130, 30);
                            alpha.Composite(image, CompositeOperator.CopyAlpha);

                            ColorAssert.AreEqual(new MagickColor("#7fff7fff7fff0000"), alpha, 0, 0);
                            ColorAssert.AreEqual(new MagickColor("#7fff7fff7fffffff"), alpha, 30, 30);
                        }
                    }
                }
コード例 #12
0
 /// <summary>
 /// Realiza uma determinada ação na imagem
 /// </summary>
 /// <param name="acao">Ação a executar</param>
 /// <param name="imagem">Imagem</param>
 public void ProcessarAcao(Acao acao, IMagickImage imagem)
 {
     if (acao is AcaoEscala escala)
     {
         imagem.Scale(new Percentage(escala.Percentagem));
     }
     else if (acao is AcaoRotacao rotacionar)
     {
         imagem.Rotate(rotacionar.Angulo);
     }
     else if (acao is AcaoTranslacao translacao)
     {
         using (var imgOr = imagem.Clone())
         {
             imagem.Colorize(MagickColors.Black, new Percentage(100));
             imagem.Composite(imgOr, translacao.X, translacao.Y);
         }
     }
     else
     {
         ProcessarAcao(RecuperarDetalhes(acao), imagem);
     }
 }
コード例 #13
0
        static public void DrawEnhancedText(
            this IMagickImage <byte> image, string text, Gravity gravity, int x, int y, MagickColor foreground,
            DrawableFont font, double fontPointSize, int maxWidth, bool ellipsize = true)
        {
            var settings = new MagickReadSettings()
            {
                BackgroundColor = MagickColors.Transparent,
                Width           = maxWidth,
                TextGravity     = gravity,
                TextAntiAlias   = false
            };

            //settings.SetDefine("pango:wrap", "char");
            if (ellipsize)
            {
                settings.SetDefine("pango:ellipsize", "end");
            }

            // Escape text for use in pango markup language
            // For some reason the text must be excaped twice otherwise it will not work
            text = SecurityElement.Escape(SecurityElement.Escape(text));

            using var textArea = new MagickImage($@"pango:<span
                size=""{fontPointSize * 1000}""
                font_family=""{ font.Family }""
                stretch=""{font.Stretch}""
                style=""{(font.Style == FontStyleType.Any ? FontStyleType.Normal : font.Style)}""
                weight=""{font.Weight}""
                foreground=""white""
                >{text}</span>", settings);

            using var colored = new MagickImage(foreground, textArea.Width, textArea.Height);
            colored.Alpha(AlphaOption.On);
            colored.Composite(textArea, CompositeOperator.Multiply, Channels.Alpha);

            image.Composite(colored, x, y, CompositeOperator.Over);
        }