Exemplo n.º 1
0
        private void UnsafeShadesOfGray()
        {
            UnsafeBitmap bmp2 = new UnsafeBitmap((Bitmap)pictureBox1.Image.Clone());
            int          x, y, r, g, b; PixelData c;
            int          f;

            bmp2.LockBitmap();
            for (y = 0; y < bmp2.Bitmap.Height; ++y)
            {
                for (x = 0; x < bmp2.Bitmap.Width; ++x)
                {
                    c = bmp2.GetPixel(x, y);
                    r = c.R;
                    g = c.G;
                    b = c.B;

                    f = (r + g + b) / 3;
                    //c = Color.FromArgb(255-r,255-g,255-b); //инверсия
                    //c = Color.FromArgb(f, f, f); // чб
                    c.R = (byte)f;
                    c.G = (byte)f;
                    c.B = (byte)f;

                    bmp2.SetPixel(x, y, c);
                }
            }
            bmp2.UnlockBitmap();
            pictureBox2.Image = bmp2.Bitmap;
        }
Exemplo n.º 2
0
        private void FastConver()
        {
            Random rnd = new Random();

            double[,] matrix = random();

            /*{
             *                { 0.01, 0.02, 0.03, 0.04, 0.05 },
             *                {-0.75,0,0.2,1,-1 },
             *                { 0,0,-0.2,1,-1},
             *                { 0,-0.5,0.2,1,-1},
             *                { 0,0,-0.2,1,-1}
             * };
             */
            UnsafeBitmap bmp2 = new UnsafeBitmap((Bitmap)pictureBox1.Image.Clone());
            int          x, y;
            double       r = 0, g = 0, b = 0;
            PixelData    c = new PixelData();

            swatch.Start();
            bmp2.LockBitmap();
            for (y = 2; y < bmp2.Bitmap.Height - 2; y++)
            {
                for (x = 2; x < bmp2.Bitmap.Width - 2; x++)
                {
                    r = 0; g = 0; b = 0;
                    for (int i = -2; i < 3; i++)
                    {
                        for (int j = -2; j < 3; j++)
                        {
                            c = bmp2.GetPixel(x + i, y + j);
                            //r += c.R / 25; g += c.G / 25; b += c.B / 25;
                            r += c.R * matrix[i + 2, j + 2]; g += c.G * matrix[i + 2, j + 2]; b += c.B * matrix[i + 2, j + 2];
                        }
                    }
                    r = r < 0 ? 0 : (r > 255) ? 255 : r;
                    g = g < 0 ? 0 : (g > 255) ? 255 : g;
                    b = b < 0 ? 0 : (b > 255) ? 255 : b;

                    c.R = (byte)r;
                    c.G = (byte)g;
                    c.B = (byte)b;
                    bmp2.SetPixel(x, y, c);
                }
            }
            bmp2.UnlockBitmap();
            swatch.Stop();

            pictureBox2.Image = bmp2.Bitmap;
        }