Ejemplo n.º 1
0
        private string Process()
        {
            try
            {
                using (MagickImage srcMagickImage = new MagickImage(_inputFilePath))
                {
                    using (MagickImage grayScaleImage = (MagickImage)srcMagickImage.Clone())
                    {
                        using (MagickImage beforeImage = new MagickImage(new MagickColor(160, 160, 160, 255), srcMagickImage.Width, srcMagickImage.Height))
                        {
                            using (MagickImage afterImage = new MagickImage(new MagickColor(56, 56, 56, 255), srcMagickImage.Width, srcMagickImage.Height))
                            {
                                grayScaleImage.Grayscale(PixelIntensityMethod.Undefined);
                                grayScaleImage.BrightnessContrast(new Percentage(10), new Percentage(10));

                                grayScaleImage.Composite(beforeImage, CompositeOperator.SoftLight);
                                grayScaleImage.Composite(afterImage, CompositeOperator.Lighten);
                                grayScaleImage.Write(_outputFilePath);

                                return(string.Empty);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }
Ejemplo n.º 2
0
        public string Execute(FileItem item, string infile, string dest, ValuePairEnumerator configData)
        {
            var conf = new EnhanceViewModel(configData);

            dest = Path.Combine(Path.GetDirectoryName(dest), Path.GetFileNameWithoutExtension(dest) + ".jpg");
            using (MagickImage image = new MagickImage(infile))
            {
                if (conf.Normalize)
                {
                    image.Normalize();
                }
                if (conf.AutoGamma)
                {
                    image.AutoGamma();
                }
                image.BrightnessContrast(new Percentage(conf.Brightness), new Percentage(conf.Contrast));
                if (conf.SContrast > 0)
                {
                    image.SigmoidalContrast(true, conf.SContrast);
                }
                if (conf.Edge)
                {
                    image.AdaptiveSharpen();
                }
                if (conf.Sharpen > 0)
                {
                    image.UnsharpMask(1.5, 1.5, conf.Sharpen / 100.0, 0.2);
                }
                image.Format = MagickFormat.Jpeg;
                image.Write(dest);
            }
            return(dest);
        }
Ejemplo n.º 3
0
        private string Process()
        {
            try
            {
                using (MagickImage srcMagickImage = new MagickImage(_inputFilePath))
                {
                    using (MagickImage sepiaImage = new MagickImage(new MagickColor(125, 125, 125, 60), srcMagickImage.Width, srcMagickImage.Height))
                    {
                        sepiaImage.SepiaTone(new Percentage(80));

                        sepiaImage.Composite(srcMagickImage, CompositeOperator.Overlay);

                        sepiaImage.BrightnessContrast(new Percentage(0), new Percentage(10));
                        sepiaImage.Modulate(new Percentage(100), new Percentage(100), new Percentage(100));

                        using (MagickImage beforeImage = new MagickImage(new MagickColor(247, 176, 15, 25), srcMagickImage.Width, srcMagickImage.Height))
                        {
                            using (MagickImage afterImage = new MagickImage(new MagickColor(0, 70, 150, 120), srcMagickImage.Width, srcMagickImage.Height))
                            {
                                sepiaImage.Composite(beforeImage, CompositeOperator.Darken);

                                sepiaImage.Composite(afterImage, CompositeOperator.Lighten);
                                sepiaImage.Write(_outputFilePath);

                                return(string.Empty);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }
Ejemplo n.º 4
0
 public override void Apply(MagickImage image)
 {
     image.BrightnessContrast(
         new Percentage(Brightness),
         new Percentage(Contrast)
         );
 }
Ejemplo n.º 5
0
        private string Process()
        {
            try
            {
                using (MagickImage srcMagickImage = new MagickImage(_inputFilePath))
                {
                    using (MagickImage clonedImage = (MagickImage)srcMagickImage.Clone())
                    {
                        using (MagickImage beforeImage = new MagickImage(new MagickColor(127, 187, 227, 51), srcMagickImage.Width, srcMagickImage.Height))
                        {
                            clonedImage.BrightnessContrast(new Percentage(0), new Percentage(10));
                            clonedImage.Modulate(new Percentage(100), new Percentage(130), new Percentage(100));

                            clonedImage.Composite(beforeImage, CompositeOperator.Overlay);
                            clonedImage.Write(_outputFilePath);

                            return(string.Empty);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }
Ejemplo n.º 6
0
 public static void threshold(string image_path, string output_path, int brightness = 20, int contrast = 20, int posterize = 2)
 {
     using (MagickImage image = new MagickImage(image_path)) {
         image.BrightnessContrast(brightness, contrast);
         image.ColorSpace = ColorSpace.Gray;
         image.Posterize(posterize);
         image.Normalize();
         image.Write(output_path);
     }
 }
        public bool OverrideTextureMaps(string textureName, double reflection, double blur, double specular)
        {
            if (CarNode == null)
            {
                return(true);
            }
            using (var image = new MagickImage(CarNode.OriginalFile.TexturesData[textureName])) {
                if (image.Width > 512 || image.Height > 512)
                {
                    image.Resize(512, 512);
                }

                image.BrightnessContrast(reflection, 1d, Channels.Red);
                image.BrightnessContrast(blur, 1d, Channels.Green);
                image.BrightnessContrast(specular, 1d, Channels.Blue);

                return(OverrideTexture(textureName, image.ToByteArray(MagickFormat.Bmp)));
            }
        }
Ejemplo n.º 8
0
        private string Process()
        {
            try
            {
                using (MagickImage srcMagickImage = new MagickImage(_inputFilePath))
                {
                    using (MagickImage sepiaImage = new MagickImage(new MagickColor(125, 125, 125, 55), srcMagickImage.Width, srcMagickImage.Height))
                    {
                        sepiaImage.SepiaTone(new Percentage(92));
                        sepiaImage.Composite(srcMagickImage, CompositeOperator.Overlay);
                        sepiaImage.BrightnessContrast(new Percentage(10), new Percentage(0));

                        using (Bitmap bitmap = new Bitmap(srcMagickImage.Width * 2, srcMagickImage.Height * 2))
                        {
                            using (Graphics graphics = Graphics.FromImage(bitmap))
                            {
                                Rectangle    rectangle = new Rectangle(0, 0, srcMagickImage.Width * 2, srcMagickImage.Height * 2);
                                GraphicsPath gp        = new GraphicsPath();
                                gp.AddEllipse(rectangle);

                                PathGradientBrush pgb = new PathGradientBrush(gp)
                                {
                                    CenterPoint    = new PointF(rectangle.Width / 2, rectangle.Height / 2),
                                    CenterColor    = Color.White,
                                    SurroundColors = new Color[] { new MagickColor(0, 0, 0, 200) }
                                };


                                graphics.FillPath(pgb, gp);

                                bitmap.Save("gradientImage.jpg", ImageFormat.Jpeg);

                                pgb.Dispose();
                                gp.Dispose();
                            }
                        }

                        using (MagickImage afterImage = new MagickImage("gradientImage.jpg"))
                        {
                            afterImage.Crop(afterImage.Width / 4, afterImage.Height / 4, afterImage.Width / 2, afterImage.Height / 2);

                            sepiaImage.Composite(afterImage, CompositeOperator.ColorBurn);
                            sepiaImage.Write(_outputFilePath);
                            sepiaImage.Dispose();

                            return(string.Empty);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }
Ejemplo n.º 9
0
        public override void Apply(MagickImage image)
        {
            var height         = image.Height;
            var viewPortHeight = Height / 100.0 * height;

            var topGradientHeight    = (int)((Offset / 100 * height) - (viewPortHeight / 2));
            var bottomGradientHeight = (int)(((100 - Offset) / 100 * height) - (viewPortHeight / 2));

            var mask = Mask(image.Width, image.Height, topGradientHeight, bottomGradientHeight);

            image.BrightnessContrast(new Percentage(0), new Percentage(Contrast));
            image.Modulate(new Percentage(100), new Percentage(Saturation), new Percentage(300));
            image.Sharpen(Sharpness, Sharpness);

            image.SetWriteMask(mask);

            image.Blur(0, Blur);
        }
Ejemplo n.º 10
0
 public bool Execute(WorkFlowCommand command, Context context)
 {
     if (context?.ImageStream == null)
     {
         return(true);
     }
     if (!CheckCondition(command, context))
     {
         return(true);
     }
     context.ImageStream.Seek(0, SeekOrigin.Begin);
     using (MagickImage image = new MagickImage(context.ImageStream))
     {
         context.ImageStream.Seek(0, SeekOrigin.Begin);
         image.BrightnessContrast(new Percentage((double)context.WorkFlow.Variables[command.Properties["Brightness"].ToString(context)].GetAsObject()),
                                  new Percentage((double)context.WorkFlow.Variables[command.Properties["Contrast"].ToString(context)].GetAsObject()));
         image.Write(context.ImageStream, MagickFormat.Bmp);
     }
     return(true);
 }
Ejemplo n.º 11
0
Archivo: Magic.cs Proyecto: lkuich/tuck
        private static void Distort(byte[] file, string path, Range brightnessRange, Range rotationRange, Range zoomRangeX, Range zoomRangeY)
        {
            var random = new Random();

            int contrast   = random.Next(brightnessRange.Min, brightnessRange.Max);
            int brightness = random.Next(brightnessRange.Min, brightnessRange.Max);
            int rotation   = random.Next(rotationRange.Min, rotationRange.Max);

            int zoomX = random.Next(zoomRangeX.Min, zoomRangeX.Max);
            int zoomY = random.Next(zoomRangeY.Min, zoomRangeY.Max);

            using (var image = new MagickImage(file))
            {
                image.Crop(zoomX, zoomY, image.Width, image.Height);
                image.BrightnessContrast(new Percentage(brightness), new Percentage(contrast));
                image.Rotate(rotation);

                var b = image.ToByteArray();
                Console.WriteLine($"Writing {path}");
                DIO.File.WriteAllBytes(path, b);
            }
        }
Ejemplo n.º 12
0
 public void Contrast()
 {
     image.BrightnessContrast((Percentage)40, (Percentage)75);
 }
Ejemplo n.º 13
0
#pragma warning disable 1998
        public async Task <String> ImageList(FileCollection fileCollection, EditorOptions editorOptions, String newPath)
#pragma warning restore 1998
        {
            // AutoMod High - SaveTo

            if (editorOptions.ManulpilationMod == ManulpilationMod.Rotate && editorOptions.OutputMod == OutputMod.SaveTo)
            {
                Console.WriteLine(@"Rotation Replace");
                foreach (FileItem t in fileCollection.Files)
                {
                    var image = new MagickImage(t.FullPath)
                    {
                        Format = MagickFormat.Unknown
                    };
                    image.Rotate(editorOptions.RotationLevel);
                    Console.WriteLine(@"RotationLevel at AutoMod High - SaveTo " + editorOptions.RotationLevel);
                    image.Write(newPath + "//" + t.Name + "." + t.Type);
                }
            }


            // AutoMod High - Replace

            if (editorOptions.ManulpilationMod == ManulpilationMod.Rotate &&
                editorOptions.OutputMod == OutputMod.ReplaceImages)
            {
                Console.WriteLine(@"Rotation Replace");
                foreach (FileItem t in fileCollection.Files)
                {
                    MagickImage image =
                        new MagickImage(t.FullPath);

                    //get given Rotation value of picture from metadata
                    //MagickImageInfo magickImageInfo = new MagickImageInfo(t.FullPath);

                    image.Format = MagickFormat.Unknown;
                    image.Rotate(editorOptions.RotationLevel);
                    image.Write(t.FullPath);
                }
            }

            // Kontrast - SaveTo
            if (editorOptions.ManulpilationMod == ManulpilationMod.Kontrast && editorOptions.OutputMod == OutputMod.SaveTo)
            {
                Console.WriteLine(@"Kontrast Replace");
                foreach (FileItem t in fileCollection.Files)
                {
                    var image = new MagickImage(t.FullPath);
                    image.Format = MagickFormat.Unknown;

                    Percentage percentage = new Percentage(editorOptions.EditorSliderLevel);
                    image.BrightnessContrast(percentage, percentage);
                    Console.WriteLine(@" Kontrast - SaveTo " + editorOptions.EditorSliderLevel);
                    image.Write(newPath + "//" + t.Name + "." + t.Type);
                }
            }

            // Kontrast - ReplaceImages
            if (editorOptions.ManulpilationMod == ManulpilationMod.Kontrast && editorOptions.OutputMod == OutputMod.ReplaceImages)
            {
                Console.WriteLine(@"Contrast Replace");
                for (int i = 0; i < fileCollection.Files.Count; ++i)
                {
                    MagickImage image =
                        new MagickImage(fileCollection.Files[i].FullPath);
                    image.Format = MagickFormat.Unknown;

                    Percentage percentage = new Percentage(editorOptions.EditorSliderLevel);

                    image.BrightnessContrast(percentage, percentage);
                    Console.WriteLine(@"Kontrast - ReplaceImages " + editorOptions.RotationLevel);
                    image.Write(fileCollection.Files[i].FullPath);
                }
            }

            return("Pictures are now Edited");
        }
Ejemplo n.º 14
0
 public async Task <byte[]> ModifyAsync(string targetImage)
 {
     using var image = new MagickImage(await HttpClient.GetByteArrayAsync(targetImage));
     image.BrightnessContrast(new Percentage(BrightnessValue), new Percentage(100));
     return(image.ToByteArray());
 }
Ejemplo n.º 15
0
        public MagickImage DoConversion(MagickImage input)
        {
            MagickImage output = new MagickImage();

            try
            {
                output = new MagickImage(input.Clone());

                foreach (OperationType optype in this.order)
                {
                    switch (optype)
                    {
                    case OperationType.BrightnessContrast:
                        if ((this.contrast != 0) || (this.brightness != 0))
                        {
                            output.BrightnessContrast((Percentage)brightness, (Percentage)contrast);
                        }
                        break;

                    case OperationType.Treshold:
                        if (do_treshold)
                        {
                            output.Threshold((Percentage)treshold);
                        }
                        break;

                    case OperationType.Gamma:
                        if (((double)gamma / 100) != 1.0)
                        {
                            output.GammaCorrect((double)gamma / 100);
                        }
                        break;

                    case OperationType.Enhance:
                        if (do_enhance)
                        {
                            output.Enhance();
                        }
                        break;

                    case OperationType.Sharpen:
                        if (do_sharpen)
                        {
                            output.Sharpen();
                        }
                        break;

                    case OperationType.NoiseFilter:
                        if (noise > 0)
                        {
                            output.ReduceNoise(noise);
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (MagickCorruptImageErrorException e)
            {
                throw e;
            }
            return(output);
        }