Ejemplo n.º 1
0
 // Cofniecie ostatniej operacji;
 internal void goBack(MyBitmap myBitmap)
 {
     Bitmap tmp = (Bitmap)myBitmap.PreviousBitmap.Clone();
     myBitmap.CurrentBitmap = myBitmap.PreviousBitmap;
     myBitmap.PreviousBitmap = tmp;
     myBitmap.updateArrays();
 }
Ejemplo n.º 2
0
        // Obraz w skali szarości;
        internal void grayScale(MyBitmap myBitmap)
        {
            myBitmap.PreviousBitmap = (Bitmap)myBitmap.CurrentBitmap.Clone();
            //Srednia skladowych       // Wykorzystanie modelu YUV
            const float rMod = 0.333f; //rMod = 0.299f;
            const float gMod = 0.333f; //gMod = 0.587f;
            const float bMod = 0.333f; //bMod = 0.114f;
            Graphics g = Graphics.FromImage(myBitmap.CurrentBitmap);

            ColorMatrix colorMatrix = new ColorMatrix(new[]
            {
                new[] {rMod, rMod, rMod, 0, 1},
                new[] {gMod, gMod, gMod, 0, 1},
                new[] {bMod, bMod, bMod, 0, 1},
                new[] {0.0f, 0.0f, 0.0f, 1, 1},
                new[] {0.0f, 0.0f, 0.0f, 0, 1}
            });

            ImageAttributes attributes = new ImageAttributes();
            attributes.SetColorMatrix(colorMatrix);
            int x = myBitmap.BitmapInfo.SizeX;
            int y = myBitmap.BitmapInfo.SizeY;
            g.DrawImage(myBitmap.CurrentBitmap, new Rectangle(0, 0, x, y), 0, 0, x, y, GraphicsUnit.Pixel, attributes);
            //myBitmap.updateArrays();
            g.Dispose();
        }
Ejemplo n.º 3
0
        // Obraz w skali szarości;
        internal void grayScale(MyBitmap myBitmap)
        {
            myBitmap.PreviousBitmap = (Bitmap)myBitmap.CurrentBitmap.Clone();
            //Srednia skladowych       // Wykorzystanie modelu YUV
            const float rMod = 0.333f; //rMod = 0.299f;
            const float gMod = 0.333f; //gMod = 0.587f;
            const float bMod = 0.333f; //bMod = 0.114f;
            Graphics    g    = Graphics.FromImage(myBitmap.CurrentBitmap);

            ColorMatrix colorMatrix = new ColorMatrix(new[]
            {
                new[] { rMod, rMod, rMod, 0, 1 },
                new[] { gMod, gMod, gMod, 0, 1 },
                new[] { bMod, bMod, bMod, 0, 1 },
                new[] { 0.0f, 0.0f, 0.0f, 1, 1 },
                new[] { 0.0f, 0.0f, 0.0f, 0, 1 }
            });

            ImageAttributes attributes = new ImageAttributes();

            attributes.SetColorMatrix(colorMatrix);
            int x = myBitmap.BitmapInfo.SizeX;
            int y = myBitmap.BitmapInfo.SizeY;

            g.DrawImage(myBitmap.CurrentBitmap, new Rectangle(0, 0, x, y), 0, 0, x, y, GraphicsUnit.Pixel, attributes);
            //myBitmap.updateArrays();
            g.Dispose();
        }
Ejemplo n.º 4
0
        // Cofniecie ostatniej operacji;
        internal void goBack(MyBitmap myBitmap)
        {
            Bitmap tmp = (Bitmap)myBitmap.PreviousBitmap.Clone();

            myBitmap.CurrentBitmap  = myBitmap.PreviousBitmap;
            myBitmap.PreviousBitmap = tmp;
            myBitmap.updateArrays();
        }
Ejemplo n.º 5
0
 public void saveBitmapAs(MyBitmap myBitmap)
 {
     if (myBitmap != null)
     {
         SaveFileDialog saveDialog = new SaveFileDialog();
         saveDialog.FileName = "moj_plik";
         saveDialog.Filter   = "Plik graficzny (*.bmp)|*.BMP; *.bmp";
         saveDialog.ShowDialog();
         myBitmap.CurrentBitmap.Save(saveDialog.FileName);
         saveDialog.Dispose();
     }
 }
Ejemplo n.º 6
0
 public void saveBitmap(MyBitmap myBitmap)
 {
     if (myBitmap != null)
     {
         DialogResult result1 = MessageBox.Show("Czy chcesz nadpisać istniejący plik: \n" + myBitmap.BitmapInfo.Path,
                                                "Zapisz", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
         if (result1 == DialogResult.Yes)
         {
             myBitmap.CurrentBitmap.Save(myBitmap.BitmapInfo.Path);
         }
     }
 }
Ejemplo n.º 7
0
 public void saveBitmapAs(MyBitmap myBitmap)
 {
     if (myBitmap != null)
     {
         SaveFileDialog saveDialog = new SaveFileDialog();
         saveDialog.FileName = "moj_plik";
         saveDialog.Filter = "Plik graficzny (*.bmp)|*.BMP; *.bmp";
         saveDialog.ShowDialog();
         myBitmap.CurrentBitmap.Save(saveDialog.FileName);
         saveDialog.Dispose();
     }
 }
Ejemplo n.º 8
0
 public void saveBitmap(MyBitmap myBitmap)
 {
     if (myBitmap != null)
     {
         DialogResult result1 = MessageBox.Show("Czy chcesz nadpisać istniejący plik: \n" + myBitmap.BitmapInfo.Path,
                 "Zapisz", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
         if (result1 == DialogResult.Yes)
         {
             myBitmap.CurrentBitmap.Save(myBitmap.BitmapInfo.Path);
         }
     }
 }
Ejemplo n.º 9
0
        // Obraz wyostrzony maską 3x3
        internal void sharpenBitmap(MyBitmap myBitmap)
        {
            myBitmap.PreviousBitmap = (Bitmap)myBitmap.CurrentBitmap.Clone();
            Bitmap sharpenImage = new Bitmap(myBitmap.BitmapInfo.SizeX, myBitmap.BitmapInfo.SizeY);
            int    filterWidth  = 3;
            int    filterHeight = 3;
            int    width        = myBitmap.BitmapInfo.SizeX;
            int    height       = myBitmap.BitmapInfo.SizeY;

            // Tablica maski.
            int[,] filter   = { { -1, -1, -1 }, { -1, 9, -1 }, { -1, -1, -1 } };
            Color[,] result = new Color[width, height];

            for (int x = 0; x < width; ++x)
            {
                for (int y = 0; y < height; ++y)
                {
                    int   red = 0, green = 0, blue = 0;
                    Color imageColor = myBitmap.CurrentBitmap.GetPixel(x, y);

                    for (int filterX = 0; filterX < filterWidth; filterX++)
                    {
                        for (int filterY = 0; filterY < filterHeight; filterY++)
                        {
                            int imageX = (x - filterWidth / 2 + filterX + width) % width;
                            int imageY = (y - filterHeight / 2 + filterY + height) % height;

                            Color bmpColor = myBitmap.CurrentBitmap.GetPixel(imageX, imageY);
                            red   += bmpColor.R * filter[filterX, filterY];
                            green += bmpColor.G * filter[filterX, filterY];
                            blue  += bmpColor.B * filter[filterX, filterY];
                        }
                        // Ustawiamy wartość na zakres <0,255> jesli nie miesci sie w tym przedziale;
                        int r = Math.Min(Math.Max(red, 0), 255);
                        int g = Math.Min(Math.Max(green, 0), 255);
                        int b = Math.Min(Math.Max(blue, 0), 255);

                        result[x, y] = Color.FromArgb(r, g, b);
                    }
                }
            }
            for (int i = 0; i < width; ++i)
            {
                for (int j = 0; j < height; ++j)
                {
                    sharpenImage.SetPixel(i, j, result[i, j]);
                }
            }
            myBitmap.CurrentBitmap = MyBitmap.convertTo24bpp(sharpenImage);
            myBitmap.updateArrays();
        }
Ejemplo n.º 10
0
 private void otwórzPlikToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (!backgroundWorker.IsBusy)
     {
         myBitmap = bmpManager.openImage();
         if (myBitmap != null)
         {
             formViewer.showBitmap(myBitmap.PreviousBitmap, pictureBox1);
             formViewer.showBitmap(myBitmap.CurrentBitmap, pictureBox2);
             formViewer.updateLabel(myBitmap.BitmapInfo.Path, labPath);
             formViewer.updateLabel(myBitmap.BitmapInfo.SizeX + " x " + myBitmap.BitmapInfo.SizeY, labRes);
         }
     }
 }
Ejemplo n.º 11
0
        // Obraz w negatywie;
        internal void inverseBitmap(MyBitmap myBitmap)
        {
            myBitmap.PreviousBitmap = (Bitmap)myBitmap.CurrentBitmap.Clone();
            Graphics g = Graphics.FromImage(myBitmap.CurrentBitmap);

            ColorMatrix colorMatrix = new ColorMatrix(new[]
            {
                new[] {-1.0f, 0.0f, 0.0f, 0, 0},
                new[] {0.0f, -1.0f, 0.0f, 0, 0},
                new[] {0.0f, 0.0f, -1.0f, 0, 0},
                new[] {0.0f, 0.0f, 0.0f, 1, 0},
                new[] {1.0f, 1.0f, 1.0f, 0, 1}
            });

            ImageAttributes attributes = new ImageAttributes();
            attributes.SetColorMatrix(colorMatrix);
            int x = myBitmap.BitmapInfo.SizeX;
            int y = myBitmap.BitmapInfo.SizeY;
            g.DrawImage(myBitmap.CurrentBitmap, new Rectangle(0, 0, x, y), 0, 0, x, y, GraphicsUnit.Pixel, attributes);
            g.Dispose();
            myBitmap.updateArrays();
        }
Ejemplo n.º 12
0
        // Obraz w negatywie;
        internal void inverseBitmap(MyBitmap myBitmap)
        {
            myBitmap.PreviousBitmap = (Bitmap)myBitmap.CurrentBitmap.Clone();
            Graphics g = Graphics.FromImage(myBitmap.CurrentBitmap);

            ColorMatrix colorMatrix = new ColorMatrix(new[]
            {
                new[] { -1.0f, 0.0f, 0.0f, 0, 0 },
                new[] { 0.0f, -1.0f, 0.0f, 0, 0 },
                new[] { 0.0f, 0.0f, -1.0f, 0, 0 },
                new[] { 0.0f, 0.0f, 0.0f, 1, 0 },
                new[] { 1.0f, 1.0f, 1.0f, 0, 1 }
            });

            ImageAttributes attributes = new ImageAttributes();

            attributes.SetColorMatrix(colorMatrix);
            int x = myBitmap.BitmapInfo.SizeX;
            int y = myBitmap.BitmapInfo.SizeY;

            g.DrawImage(myBitmap.CurrentBitmap, new Rectangle(0, 0, x, y), 0, 0, x, y, GraphicsUnit.Pixel, attributes);
            g.Dispose();
            myBitmap.updateArrays();
        }
Ejemplo n.º 13
0
        // Obraz wyostrzony maską 3x3
        internal void sharpenBitmap(MyBitmap myBitmap)
        {
            myBitmap.PreviousBitmap = (Bitmap)myBitmap.CurrentBitmap.Clone();
            Bitmap sharpenImage = new Bitmap(myBitmap.BitmapInfo.SizeX, myBitmap.BitmapInfo.SizeY);
            int filterWidth = 3;
            int filterHeight = 3;
            int width = myBitmap.BitmapInfo.SizeX;
            int height = myBitmap.BitmapInfo.SizeY;
            // Tablica maski.
            int[,] filter = { { -1, -1, -1 }, { -1, 9, -1 }, { -1, -1, -1 } };
            Color[,] result = new Color[width, height];

            for (int x = 0; x < width; ++x)
            {
                for (int y = 0; y < height; ++y)
                {
                    int red = 0, green = 0, blue = 0;
                    Color imageColor = myBitmap.CurrentBitmap.GetPixel(x, y);

                    for (int filterX = 0; filterX < filterWidth; filterX++)
                    {
                        for (int filterY = 0; filterY < filterHeight; filterY++)
                        {
                            int imageX = (x - filterWidth / 2 + filterX + width) % width;
                            int imageY = (y - filterHeight / 2 + filterY + height) % height;

                            Color bmpColor = myBitmap.CurrentBitmap.GetPixel(imageX, imageY);
                            red += bmpColor.R * filter[filterX, filterY];
                            green += bmpColor.G * filter[filterX, filterY];
                            blue += bmpColor.B * filter[filterX, filterY];
                        }
                        // Ustawiamy wartość na zakres <0,255> jesli nie miesci sie w tym przedziale;
                        int r = Math.Min(Math.Max(red, 0), 255);
                        int g = Math.Min(Math.Max(green, 0), 255);
                        int b = Math.Min(Math.Max(blue, 0), 255);

                        result[x, y] = Color.FromArgb(r, g, b);
                    }
                }
            }
            for (int i = 0; i < width; ++i)
            {
                for (int j = 0; j < height; ++j) sharpenImage.SetPixel(i, j, result[i, j]);
            }
            myBitmap.CurrentBitmap = MyBitmap.convertTo24bpp(sharpenImage);
            myBitmap.updateArrays();
        }