完结超酷的图像效果

如若您认为C#创设的办法字相比有意思,
不过还认为没看够,不舒坦,那么自身前日就让您一饱眼福,
看看C#怎样构建的效果超酷的图像.

(注: 作者在此以前曾写过类似的篇章, 但未有规律表达, 代码注释不够详细,
也一贯不附相应的
德姆o…因而只要您以为仿佛哪看过类似的小说能够看看自家在此以前写的…)

 

为了演示前边的功效, 这里有不可缺少先让我们看看后天的原有图片: ISI美国篮球专门的学业联赛EVA
~~~~

银河至尊游戏官网 1

 

一. 底片效果
原理: GetPixel方法赢得每一点像素的值,
然后再使用SetPixel方法将取反后的颜色值设置到对应的点.
效果图: 
银河至尊游戏官网 2

代码完结:

二. 浮雕效果

原理: 对图像像素点的像素值分别与紧邻像素点的像素值相减后拉长12八,
然后将其看做新的像素点的值.

效果图:

银河至尊游戏官网 3

代码达成:

银河至尊游戏官网 4银河至尊游戏官网 5

private void button1_Click(object sender, EventArgs e)
        {
            //以底片效果显示图像
            try
            {
                int Height = this.pictureBox1.Image.Height;
                int Width = this.pictureBox1.Image.Width;
                Bitmap newbitmap = new Bitmap(Width, Height);
                Bitmap oldbitmap = (Bitmap)this.pictureBox1.Image;
                Color pixel;
                for (int x = 1; x < Width; x++)
                {
                    for (int y = 1; y < Height; y++)
                    {
                        int r, g, b;
                        pixel = oldbitmap.GetPixel(x, y);
                        r = 255 - pixel.R;
                        g = 255 - pixel.G;
                        b = 255 - pixel.B;
                        newbitmap.SetPixel(x, y, Color.FromArgb(r, g, b));
                    }
                }
                this.pictureBox1.Image = newbitmap;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

View Code

 

3. 黑白效果

规律: 彩色图像处理成黑白效果常常有叁种算法;

(一).最大值法: 使每一种像素点的 昂Cora, G, B 值等于原像素点的 CR-VGB (颜色值)
中最大的二个;

(二).平均值法: 使用各类像素点的 Kuga,G,B值等于原像素点的锐界GB值的平均值;

(叁).加权平均值法: 对各样像素点的 RAV4, G, B值实行加权

    —自感觉第二种方式做出来的长短效果图像最 “真实”.

效果图:

银河至尊游戏官网 6

代码完结:

银河至尊游戏官网 7银河至尊游戏官网 8

 private void button1_Click(object sender, EventArgs e)
        {
            //以黑白效果显示图像
            try
            {
                int Height = this.pictureBox1.Image.Height;
                int Width = this.pictureBox1.Image.Width;
                Bitmap newBitmap = new Bitmap(Width, Height);
                Bitmap oldBitmap = (Bitmap)this.pictureBox1.Image;
                Color pixel;
                for (int x = 0; x < Width; x++)
                    for (int y = 0; y < Height; y++)
                    {
                        pixel = oldBitmap.GetPixel(x, y);
                        int r, g, b, Result = 0;
                        r = pixel.R;
                        g = pixel.G;
                        b = pixel.B;
                        //实例程序以加权平均值法产生黑白图像
                        int iType =2;
                        switch (iType)
                        {
                            case 0://平均值法
                                Result = ((r + g + b) / 3);
                                break;
                            case 1://最大值法
                                Result = r > g ? r : g;
                                Result = Result > b ? Result : b;
                                break;
                            case 2://加权平均值法
                                Result = ((int)(0.7 * r) + (int)(0.2 * g) + (int)(0.1 * b));
                                break;
                        }
                        newBitmap.SetPixel(x, y, Color.FromArgb(Result, Result, Result));
                    }
                this.pictureBox1.Image = newBitmap;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "信息提示");
            }
        }

View Code

 

四. 柔化效果

原理: 当前像素点与周边像素点的水彩差异一点都不小时取其平均值.

效果图:

银河至尊游戏官网 9

代码落成:

 private void button1_Click(object sender, EventArgs e)
        {
            //以柔化效果显示图像
            try
            {
                int Height = this.pictureBox1.Image.Height;
                int Width = this.pictureBox1.Image.Width;
                Bitmap bitmap = new Bitmap(Width, Height);
                Bitmap MyBitmap = (Bitmap)this.pictureBox1.Image;
                Color pixel;
                //高斯模板
                int[] Gauss ={ 1, 2, 1, 2, 4, 2, 1, 2, 1 };
                for (int x = 1; x < Width - 1; x++)
                    for (int y = 1; y < Height - 1; y++)
                    {
                        int r = 0, g = 0, b = 0;
                        int Index = 0;
                        for (int col = -1; col <= 1; col++)
                            for (int row = -1; row <= 1; row++)
                            {
                                pixel = MyBitmap.GetPixel(x + row, y + col);
                                r += pixel.R * Gauss[Index];
                                g += pixel.G * Gauss[Index];
                                b += pixel.B * Gauss[Index];
                                Index++;
                            }
                        r /= 16;
                        g /= 16;
                        b /= 16;
                        //处理颜色值溢出
                        r = r > 255 ? 255 : r;
                        r = r < 0 ? 0 : r;
                        g = g > 255 ? 255 : g;
                        g = g < 0 ? 0 : g;
                        b = b > 255 ? 255 : b;
                        b = b < 0 ? 0 : b;
                        bitmap.SetPixel(x - 1, y - 1, Color.FromArgb(r, g, b));
                    }
                this.pictureBox1.Image = bitmap;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "信息提示");
            }
        }

 

伍.锐化效果

规律:特出体现颜色值大(即产生形体边缘)的像素点.

效果图:

银河至尊游戏官网 10

兑今世码:

银河至尊游戏官网 11银河至尊游戏官网 12

private void button1_Click(object sender, EventArgs e)
        {
            //以锐化效果显示图像
            try
            {
                int Height = this.pictureBox1.Image.Height;
                int Width = this.pictureBox1.Image.Width;
                Bitmap newBitmap = new Bitmap(Width, Height);
                Bitmap oldBitmap = (Bitmap)this.pictureBox1.Image;
                Color pixel;
                //拉普拉斯模板
                int[] Laplacian ={ -1, -1, -1, -1, 9, -1, -1, -1, -1 };
                for (int x = 1; x < Width - 1; x++)
                    for (int y = 1; y < Height - 1; y++)
                    {
                        int r = 0, g = 0, b = 0;
                        int Index = 0;
                        for (int col = -1; col <= 1; col++)
                            for (int row = -1; row <= 1; row++)
                            {
                                pixel = oldBitmap.GetPixel(x + row, y + col); r += pixel.R * Laplacian[Index];
                                g += pixel.G * Laplacian[Index];
                                b += pixel.B * Laplacian[Index];
                                Index++;
                            }
                        //处理颜色值溢出
                        r = r > 255 ? 255 : r;
                        r = r < 0 ? 0 : r;
                        g = g > 255 ? 255 : g;
                        g = g < 0 ? 0 : g;
                        b = b > 255 ? 255 : b;
                        b = b < 0 ? 0 : b;
                        newBitmap.SetPixel(x - 1, y - 1, Color.FromArgb(r, g, b));
                    }
                this.pictureBox1.Image = newBitmap;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "信息提示");
            }
        }

View Code

 

6. 雾化效果

规律: 在图像中引进一定的放四值, 打乱图像中的像素值

效果图:

银河至尊游戏官网 13

贯彻代码:

银河至尊游戏官网 14银河至尊游戏官网 15

private void button1_Click(object sender, EventArgs e)
        {
            //以雾化效果显示图像
            try
            {
                int Height = this.pictureBox1.Image.Height;
                int Width = this.pictureBox1.Image.Width;
                Bitmap newBitmap = new Bitmap(Width, Height);
                Bitmap oldBitmap = (Bitmap)this.pictureBox1.Image;
                Color pixel;
                for (int x = 1; x < Width - 1; x++)
                    for (int y = 1; y < Height - 1; y++)
                    {
                        System.Random MyRandom = new Random();
                        int k = MyRandom.Next(123456);
                        //像素块大小
                        int dx = x + k % 19;
                        int dy = y + k % 19;
                        if (dx >= Width)
                            dx = Width - 1;
                        if (dy >= Height)
                            dy = Height - 1;
                        pixel = oldBitmap.GetPixel(dx, dy);
                        newBitmap.SetPixel(x, y, pixel);
                    }
                this.pictureBox1.Image = newBitmap;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "信息提示");
            }
        }

View Code

 

七. 普照效果

原理: 对图像中的某一限制内的像素的亮度分别开始展览管理.

效果图:

银河至尊游戏官网 16

福衢寿车代码:

银河至尊游戏官网 17银河至尊游戏官网 18

private void button1_Click(object sender, EventArgs e)
        {
            //以光照效果显示图像
            Graphics MyGraphics = this.pictureBox1.CreateGraphics();
            MyGraphics.Clear(Color.White);
            Bitmap MyBmp = new Bitmap(this.pictureBox1.Image, this.pictureBox1.Width, this.pictureBox1.Height);
            int MyWidth = MyBmp.Width;
            int MyHeight = MyBmp.Height;
            Bitmap MyImage = MyBmp.Clone(new RectangleF(0, 0, MyWidth, MyHeight), System.Drawing.Imaging.PixelFormat.DontCare);
            int A = Width / 2;
            int B = Height / 2;
            //MyCenter图片中心点,发亮此值会让强光中心发生偏移
            Point MyCenter = new Point(MyWidth / 2, MyHeight / 2);
            //R强光照射面的半径,即”光晕”
            int R = Math.Min(MyWidth / 2, MyHeight / 2);
            for (int i = MyWidth - 1; i >= 1; i--)
            {
                for (int j = MyHeight - 1; j >= 1; j--)
                {
                    float MyLength = (float)Math.Sqrt(Math.Pow((i - MyCenter.X), 2) + Math.Pow((j - MyCenter.Y), 2));
                    //如果像素位于”光晕”之内
                    if (MyLength < R)
                    {
                        Color MyColor = MyImage.GetPixel(i, j);
                        int r, g, b;
                        //220亮度增加常量,该值越大,光亮度越强
                        float MyPixel = 220.0f * (1.0f - MyLength / R);
                        r = MyColor.R + (int)MyPixel;
                        r = Math.Max(0, Math.Min(r, 255));
                        g = MyColor.G + (int)MyPixel;
                        g = Math.Max(0, Math.Min(g, 255));
                        b = MyColor.B + (int)MyPixel;
                        b = Math.Max(0, Math.Min(b, 255));
                        //将增亮后的像素值回写到位图
                        Color MyNewColor = Color.FromArgb(255, r, g, b);
                        MyImage.SetPixel(i, j, MyNewColor);
                    }
                }
                //重新绘制图片
                MyGraphics.DrawImage(MyImage, new Rectangle(0, 0, MyWidth, MyHeight));
            }

        }
    }

View Code

 

八.百叶窗效果

原理:(1).垂直百叶窗效果:

基于窗口或图像的莫斯中国科学技术大学学或宽度和定制的百叶窗显示条宽度总计百叶窗突显的条数据 ;

据他们说窗口或图像的万丈或宽度定制百叶窗突显条数据总括百窗展现的条宽度.

(二).水平百叶窗效果: 原理同上,只是绘制像素点初始的坐标不一致.

效果图:

银河至尊游戏官网 19     银河至尊游戏官网 20

贯彻代码:
笔直百叶窗

银河至尊游戏官网 21银河至尊游戏官网 22

private void button1_Click(object sender, EventArgs e)
        {
            //垂直百叶窗显示图像
            try
            {
                MyBitmap = (Bitmap)this.pictureBox1.Image.Clone();
                int dw = MyBitmap.Width / 30;
                int dh = MyBitmap.Height;
                Graphics g = this.pictureBox1.CreateGraphics();
                g.Clear(Color.Gray);
                Point[] MyPoint = new Point[30];
                for (int x = 0; x < 30; x++)
                {
                    MyPoint[x].Y = 0;
                    MyPoint[x].X = x * dw;
                }
                Bitmap bitmap = new Bitmap(MyBitmap.Width, MyBitmap.Height);
                for (int i = 0; i < dw; i++)
                {
                    for (int j = 0; j < 30; j++)
                    {
                        for (int k = 0; k < dh; k++)
                        {
                            bitmap.SetPixel(MyPoint[j].X + i, MyPoint[j].Y + k,
                            MyBitmap.GetPixel(MyPoint[j].X + i, MyPoint[j].Y + k));
                        }
                    }
                    this.pictureBox1.Refresh();
                    this.pictureBox1.Image = bitmap;
                    System.Threading.Thread.Sleep(100);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "信息提示");
            }

        }

View Code

水平百叶窗

银河至尊游戏官网 23银河至尊游戏官网 24

private void button3_Click(object sender, EventArgs e)
        {
            //水平百叶窗显示图像
            try
            {
                MyBitmap = (Bitmap)this.pictureBox1.Image.Clone();
                int dh = MyBitmap.Height / 20;
                int dw = MyBitmap.Width;
                Graphics g = this.pictureBox1.CreateGraphics();
                g.Clear(Color.Gray);
                Point[] MyPoint = new Point[20];
                for (int y = 0; y < 20; y++)
                {
                    MyPoint[y].X = 0;
                    MyPoint[y].Y = y * dh;
                }
                Bitmap bitmap = new Bitmap(MyBitmap.Width, MyBitmap.Height);
                for (int i = 0; i < dh; i++)
                {
                    for (int j = 0; j < 20; j++)
                    {
                        for (int k = 0; k < dw; k++)
                        {
                            bitmap.SetPixel(MyPoint[j].X + k, MyPoint[j].Y + i, MyBitmap.GetPixel(MyPoint[j].X + k, MyPoint[j].Y + i));
                        }
                    }
                    this.pictureBox1.Refresh();
                    this.pictureBox1.Image = bitmap;
                    System.Threading.Thread.Sleep(100);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "信息提示");
            }
        }

View Code

 

九.纽伦堡克意义

原理:
鲜明图像的随便地点点和规池州安克块的深浅,然后德雷斯顿克块图像覆盖随机点就可以.

效果图:

银河至尊游戏官网 25

落到实处代码:

银河至尊游戏官网 26银河至尊游戏官网 27

private void button1_Click(object sender, EventArgs e)
        {
            //以马赛克效果显示图像
            try
            {
                int dw = MyBitmap.Width / 50;
                int dh = MyBitmap.Height / 50;
                Graphics g = this.pictureBox1.CreateGraphics();
                g.Clear(Color.Gray);
                Point[] MyPoint = new Point[2500];
                for (int x = 0; x < 50; x++)
                    for (int y = 0; y < 50; y++)
                    {
                        MyPoint[x * 50 + y].X = x * dw;
                        MyPoint[x * 50 + y].Y = y * dh;
                    }
                Bitmap bitmap = new Bitmap(MyBitmap.Width, MyBitmap.Height);
                for (int i = 0; i < 10000; i++)
                {
                    System.Random MyRandom = new Random();
                    int iPos = MyRandom.Next(2500);
                    for (int m = 0; m < dw; m++)
                        for (int n = 0; n < dh; n++)
                        {
                            bitmap.SetPixel(MyPoint[iPos].X + m, MyPoint[iPos].Y + n, MyBitmap.GetPixel(MyPoint[iPos].X + m, MyPoint[iPos].Y + n));
                        }
                    this.pictureBox1.Refresh();
                    this.pictureBox1.Image = bitmap;
                }
                for (int i = 0; i < 2500; i++)
                    for (int m = 0; m < dw; m++)
                        for (int n = 0; n < dh; n++)
                        {
                            bitmap.SetPixel(MyPoint[i].X + m, MyPoint[i].Y + n, MyBitmap.GetPixel(MyPoint[i].X + m, MyPoint[i].Y + n));
                        }
                this.pictureBox1.Refresh();
                this.pictureBox1.Image = bitmap;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "信息提示");
            }
        }

View Code

 

10. 摄影效果

原理: 对图像中某1限制内的像素引进自由值.

效果图:

银河至尊游戏官网 28

完结代码:

银河至尊游戏官网 29银河至尊游戏官网 30

private void button1_Click(object sender, EventArgs e)
         {
            //以油画效果显示图像
            Graphics g = this.panel1.CreateGraphics();
            //Bitmap bitmap = this.MyBitmap;
            //取得图片尺寸
            int width = MyBitmap.Width;
            int height = MyBitmap.Height;
            RectangleF rect = new RectangleF(0, 0, width, height);
            Bitmap img = MyBitmap.Clone(rect, System.Drawing.Imaging.PixelFormat.DontCare);
            //产生随机数序列
            Random rnd = new Random();
            //取不同的值决定油画效果的不同程度
            int iModel = 2;
            int i = width - iModel;
            while (i > 1)
            {
                int j = height - iModel;
                while (j > 1)
                {
                    int iPos = rnd.Next(100000) % iModel;
                    //将该点的RGB值设置成附近iModel点之内的任一点
                    Color color = img.GetPixel(i + iPos, j + iPos);
                    img.SetPixel(i, j, color);
                    j = j - 1;
                }
                i = i - 1;
            }
            //重新绘制图像
            g.Clear(Color.White);
            g.DrawImage(img, new Rectangle(0, 0, width, height)); 
        }

View Code

 

10一: 扭曲效用

原理: 将图像缩放为1个非矩形的1律肆边形就可以

效果图:

银河至尊游戏官网 31

兑今世码:

银河至尊游戏官网 32银河至尊游戏官网 33

        private void button1_Click(object sender, EventArgs e)
        {
           //以扭曲效果显示图像
            if (h == panel1.Height/2)
            {
                w = 0;
                h = 0;
            }
            Size offset =new Size (w++,h++);//设置偏移量
            Graphics g = panel1.CreateGraphics();
            Rectangle rect = this.panel1.ClientRectangle;
            Point[] points = new Point[3];
            points[0] = new Point(rect.Left+offset.Width ,rect.Top +offset .Height);
            points[1] = new Point(rect.Right, rect.Top + offset.Height);
            points[2] = new Point(rect.Left, rect.Bottom - offset.Height);
            g.Clear(Color.White);
            g.DrawImage(MyBitmap, points);
        }

View Code

 

拾二.积木作用

原理: 对图像中的各样像素点重视(即加大分像素的颜色值)着色.

效果图:

银河至尊游戏官网 34

银河至尊游戏官网,贯彻代码:

银河至尊游戏官网 35银河至尊游戏官网 36

private void button1_Click(object sender, EventArgs e)
        {
            //以积木效果显示图像
            try
            {
                Graphics myGraphics = this.panel1.CreateGraphics ();
                //Bitmap myBitmap = new Bitmap(this.BackgroundImage);
                int myWidth, myHeight, i, j, iAvg, iPixel;
                Color myColor, myNewColor;
                RectangleF myRect;
                myWidth = MyBitmap.Width;
                myHeight = MyBitmap.Height;
                myRect = new RectangleF(0, 0, myWidth, myHeight);
                Bitmap bitmap = MyBitmap.Clone(myRect, System.Drawing.Imaging.PixelFormat.DontCare);
                i = 0;
                while (i < myWidth - 1)
                {
                    j = 0;
                    while (j < myHeight - 1)
                    {
                        myColor = bitmap.GetPixel(i, j);
                        iAvg = (myColor.R + myColor.G + myColor.B) / 3;
                        iPixel = 0;
                        if (iAvg >= 128)
                            iPixel = 255;
                        else
                            iPixel = 0;
                        myNewColor = Color.FromArgb(255, iPixel, iPixel, iPixel);
                        bitmap.SetPixel(i, j, myNewColor);
                        j = j + 1;
                    }
                    i = i + 1;
                }
                myGraphics.Clear(Color.WhiteSmoke);
                myGraphics.DrawImage(bitmap, new Rectangle(0, 0, myWidth, myHeight));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "信息提示");
            }
        }

View Code

 

表达.这几个基本上为静态图. 前面会有图像的动态展现. 如分块合成图像,
四周扩散呈现图像, 上下对接显示图像等.

      这个恐怕能证美素佳儿下
PPT可能手提式有线电话机中的图片效果管理程序是假如做出来的.原理应该是相通的.

      制作图像相似常用的类有: Bitmap; Graphics; Rectangle;Color;
用到的章程是 Graphics类的DrawImage;

      此措施共有三1九个版本, 作者习贯用 DrawImage(“图像”, “图框”) 版本.

     
因为这一个本子的沉思是最轻便易行的—-把一张**地图像装在三个**地框里!
(**表示某种意义的图像和某种意义的框)

      如. g.DrawImage(new Bitmap(“myPicture”), new Rectangle(0, 0,
myWidth, myHeight));

      呵呵, 到此

     希望对大家全部援助.

出处:http://www.cnblogs.com/ziyiFly/archive/2008/09/23/1296815.html

相关文章