Exemple #1
0
 public void grayScaleMode(GrayScaleMode scaleMode)
 {
     modifiedImage  = ImageProcessing.grayScale(image, scaleMode);
     imageMode      = ImageMode.Grayscale;
     this.scaleMode = scaleMode;
     changeBitmap(getCurrentImage());
 }
Exemple #2
0
        public ImageForm(string imagePath, Main owner)
        {
            InitializeComponent();

            this.owner = owner;
            Owner      = owner;

            imageMode = ImageMode.Default;
            scaleMode = GrayScaleMode.Null;

            filter = new ColorFilter();

            this.imagePath = imagePath;
            using (var bmpTemp = new Bitmap(imagePath))
            {
                image         = new Bitmap(bmpTemp);
                originalImage = new Bitmap(bmpTemp);
            }

            Text             = imagePath;
            pictureBox.Image = image;

            MaximumSize = new Size(owner.Width - 100, owner.Height - 150);
            setSizeAuto();
        }
        public static Bitmap grayScale(Bitmap image, GrayScaleMode mode)
        {
            Bitmap newImage = new Bitmap(image.Width, image.Height);

            for (int y = 0; y < image.Height; y++)
            {
                for (int x = 0; x < image.Width; x++)
                {
                    int gray = 0;
                    int R    = image.GetPixel(x, y).R;
                    int G    = image.GetPixel(x, y).G;
                    int B    = image.GetPixel(x, y).B;
                    switch (mode)
                    {
                    case GrayScaleMode.Average:
                        gray = (R + G + B) / 3;
                        break;

                    case GrayScaleMode.Luma:
                        gray = (int)Math.Round(R * 0.2126 + G * 0.7152 + B * 0.0722, 0);
                        break;

                    case GrayScaleMode.Desaturation:
                        gray = (Math.Max(Math.Max(R, G), B) + Math.Min(Math.Min(R, G), B)) / 2;
                        break;

                    case GrayScaleMode.DecompositionMin:
                        gray = Math.Min(Math.Min(R, G), B);
                        break;

                    case GrayScaleMode.DecompositionMax:
                        gray = Math.Max(Math.Max(R, G), B);
                        break;
                    }
                    newImage.SetPixel(x, y, Color.FromArgb(gray, gray, gray));
                }
            }
            return(newImage);
        }
Exemple #4
0
 public void changeMode(ImageMode mode)
 {
     imageMode = mode;
     scaleMode = GrayScaleMode.Null;
     changeBitmap(getCurrentImage());
 }