Exemple #1
0
 public void ColorizeBlock(Rectangle rect)
 {
     if (Colored == null)
         Colored = new Bitmap(originalMap);
     HueModifier hue = new HueModifier(huetransformator);
     hue.ApplyInPlace(Colored, rect);
     pictureBox3.Image = Colored;
 }
Exemple #2
0
        private void Hue_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            HueLabel.Content = Hue.Value;
            hue = (int)Hue.Value;

            if (mainPhoto != null)
            {
                hm = new HueModifier(hue);
                System.Drawing.Bitmap tmp = hm.Apply((System.Drawing.Bitmap)mainPhoto.Clone());
                //BitmapImage tmpBmpIs = ToBitmapImage(tmp);

                Photography.Source = ToBitmapImage(tmp);

                UpdateHistograms(tmp);
                UpdateChannelPreviews(tmp);
            }
        }
Exemple #3
0
        public static bool ColorCorrections(string fileName, int brightness, int contrast, double gamma, int hue, float saturation)
        {
            if (String.IsNullOrEmpty(fileName)) throw new ArgumentNullException("fileName");

            bool result = false;

            using (var ms = new MemoryStream(File.ReadAllBytes(fileName)))
            {
                using (Bitmap bmp = new Bitmap(ms))
                {
                    //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-255, +255] default 10
                    if (brightness >= -255 && brightness != 0 && brightness <= 255)
                    {
                        BrightnessCorrection filter = new BrightnessCorrection(brightness);
                        filter.ApplyInPlace(bmp);
                        result = true;
                    }

                    //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-127, +127] default 10
                    if (contrast >= -127 && contrast != 0 && contrast <= 127)
                    {
                        ContrastCorrection filter = new ContrastCorrection(contrast);
                        filter.ApplyInPlace(bmp);
                        result = true;
                    }

                    //The filter accepts 8 bpp grayscale and 24 bpp color images for processing, value [0.1, 5.0] default 1.0
                    if (gamma >= 0.1D && gamma != 1D && gamma <= 5D)
                    {
                        GammaCorrection filter = new GammaCorrection(gamma);
                        filter.ApplyInPlace(bmp);
                        result = true;
                    }

                    //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-180, +180] default 0
                    if (hue >= -180 && hue != 0 && hue <= 180)
                    {
                        HueModifier filter = new HueModifier(hue);
                        filter.ApplyInPlace(bmp);
                        result = true;
                    }

                    //The filter accepts 24 and 32 bpp color images for processing, value specified percentage [-1, +1] default 0.1
                    if (saturation >= -100f && saturation != 0f && saturation <= 100f)
                    {
                        SaturationCorrection filter = new SaturationCorrection(saturation / 100);
                        filter.ApplyInPlace(bmp);
                        result = true;
                    }

                    bmp.Save(fileName);
                }
            }

            return result;
        }
Exemple #4
0
        public void ColorizeBlock(int blockID, byte regionID)
        {
            regions[blockID] = regionID;
            if(Colored == null)
                Colored = new Bitmap(originalMap);

            Rectangle rect = CalculateRectangle(blockID);
            int huetransform;
            if (regionID < regionHUE.Length)
                huetransform = regionID == 0xFF ? 0 : regionHUE[regionID];
            else huetransform = 0;
            if (regionID == 255) return;
            HueModifier hue = new HueModifier(huetransform);
            hue.ApplyInPlace(Colored, rect);
        }
Exemple #5
0
        public static BitmapSource ColorCorrections(BitmapSource source, int brightness, int contrast, double gamma, int hue, float saturation)
        {
            if (source == null) throw new ArgumentNullException("source");

            BitmapSource output = null;

            if (source.Format == PixelFormats.Bgr32 && gamma != 1D)
            {
                source = new FormatConvertedBitmap(source, PixelFormats.Bgr24, null, 0);
            }

            using (Bitmap bmp = Convert(source))
            {
                int bpp = source.Format.BitsPerPixel;

                if (bpp == 8 || bpp == 24 || bpp == 32)
                {
                    //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-255, +255] default 10
                    if (brightness >= -255 && brightness != 0 && brightness <= 255)
                    {
                        BrightnessCorrection filter = new BrightnessCorrection(brightness);
                        filter.ApplyInPlace(bmp);
                    }

                    //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-127, +127] default 10
                    if (contrast >= -127 && contrast != 0 && contrast <= 127)
                    {
                        ContrastCorrection filter = new ContrastCorrection(contrast);
                        filter.ApplyInPlace(bmp);
                    }
                }

                if (bpp == 8 || bpp == 24)
                {
                    //The filter accepts 8 bpp grayscale and 24 bpp color images for processing, value [0.1, 5.0] default 1.0
                    if (gamma >= 0.1D && gamma != 1D && gamma <= 5D)
                    {
                        GammaCorrection filter = new GammaCorrection(gamma);
                        filter.ApplyInPlace(bmp);
                    }
                }

                if (bpp == 8 || bpp == 24 || bpp == 32)
                {
                    //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-180, +180] default 0
                    if (hue >= -180 && hue != 0 && hue <= 180)
                    {
                        HueModifier filter = new HueModifier(hue);
                        filter.ApplyInPlace(bmp);
                    }
                }

                if (bpp == 24 || bpp == 32)
                {
                    //The filter accepts 24 and 32 bpp color images for processing, value specified percentage [-1, +1] default 0.1
                    if (saturation >= -100f && saturation != 0f && saturation <= 100f)
                    {
                        SaturationCorrection filter = new SaturationCorrection(saturation / 100);
                        filter.ApplyInPlace(bmp);
                    }
                }

                output = Convert(bmp);
            }

            return CloneImage(output);
        }