制作超酷图像效果

假使您觉得C#塑造的艺术字正如好玩,
但是还觉得没看够,可是瘾,那么自个儿后天就让您一饱眼福,
看看C#怎么创造的成效超酷的图像.
(注: 小编事先曾写过类似的稿子, 但未有规律表明, 代码注释不够详细,
也绝非附相应的
德姆o…由此1旦你觉得好像哪看过类似的稿子能够看看自身事先写的…)

为了演示前边的机能, 那里有不可或缺先让大家看看今天的原有图片: ISI美职篮EVA
~~~~
附件: 2008092313094598.jpg

壹. 底片效果
原理: GetPixel方法得到每一点像素的值,
然后再利用SetPixel方法将取反后的颜色值设置到相应的点.
效果图:
附件: 2008092313082497.jpg
代码实现:
底片效果

  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. //以底片效果呈现图像
  4. try
  5. {
  6. int Height = this.pictureBox1.Image.Height;
  7. int Width = this.pictureBox1.Image.Width;
  8. Bitmap newbitmap = new Bitmap(Width, Height);
  9. Bitmap oldbitmap = (Bitmap)this.pictureBox1.Image;
  10. Color pixel;
  11. for (int x = 1; x < Width; x++)
  12. {
  13. for (int y = 1; y < Height; y++)
  14. {
  15. int r, g, b;
  16. pixel = oldbitmap.GetPixel(x, y);
  17. r = 255 – pixel.R;
  18. g = 255 – pixel.G;
  19. b = 255 – pixel.B;
  20. newbitmap.SetPixel(x, y, Color.FromArgb(r, g, b));
  21. }
  22. }
  23. this.pictureBox1.Image = newbitmap;
  24. }
  25. catch (Exception ex)
  26. {
  27. MessageBox.Show(ex.Message, “音讯提示”, Message博克斯Buttons.OK,
    MessageBoxIcon.Information);
  28. }
  29. }

复制代码

2. 浮雕效果
规律: 对图像像素点的像素值分别与隔壁像素点的像素值相减后拉长128,
然后将其当作新的像素点的值.
效果图:
附件: 2008092313164752.jpg
代码达成:
浮雕效果

  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. //以浮雕效果呈现图像
  4. try
  5. {
  6. int Height = this.pictureBox1.Image.Height;
  7. int Width = this.pictureBox1.Image.Width;
  8. Bitmap newBitmap = new Bitmap(Width, Height);
  9. Bitmap oldBitmap = (Bitmap)this.pictureBox1.Image;
  10. Color pixel1, pixel2;
  11. for (int x = 0; x < Width – 1; x++)
  12. {
  13. for (int y = 0; y < Height – 1; y++)
  14. {
  15. int r = 0, g = 0, b = 0;
  16. pixel1 = oldBitmap.GetPixel(x, y);
  17. pixel2 = oldBitmap.GetPixel(x + 1, y + 1);
  18. r = Math.Abs(pixel1.R – pixel2.R + 128);
  19. g = Math.Abs(pixel1.G – pixel2.G + 128);
  20. b = Math.Abs(pixel1.B – pixel2.B + 128);
  21. if (r > 255)
  22. r = 255;
  23. if (r < 0)
  24. r = 0;
  25. if (g > 255)
  26. g = 255;
  27. if (g < 0)
  28. g = 0;
  29. if (b > 255)
  30. b = 255;
  31. if (b < 0)
  32. b = 0;
  33. newBitmap.SetPixel(x, y, Color.FromArgb(r, g, b));
  34. }
  35. }
  36. this.pictureBox1.Image = newBitmap;
  37. }
  38. catch (Exception ex)
  39. {
  40. MessageBox.Show(ex.Message, “音讯提醒”, Message博克斯Buttons.OK,
    MessageBoxIcon.Information);
  41. }
  42. }

复制代码

三. 黑白效果
原理: 彩色图像处理成黑白效果一般有三种算法;
(壹).最大值法: 使各类像素点的 Odyssey, G, B 值等于原像素点的 牧马人GB (颜色值)
中最大的2个;
(2).平均值法: 使用各类像素点的 中华V,G,B值等于原像素点的福睿斯GB值的平均值;
(三).加权平均值法: 对各样像素点的 奥德赛, G, B值举办加权
    —自认为第两种办法做出来的是非曲直效果图像最 “真实”.
效果图:
附件: 2008092313241741.jpg
代码完结:
黑白效果

  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. //以黑白效果显示图像
  4. try
  5. {
  6. int Height = this.pictureBox1.Image.Height;
  7. int Width = this.pictureBox1.Image.Width;
  8. Bitmap newBitmap = new Bitmap(Width, Height);
  9. Bitmap oldBitmap = (Bitmap)this.pictureBox1.Image;
  10. Color pixel;
  11. for (int x = 0; x < Width; x++)
  12. for (int y = 0; y < Height; y++)
  13. {
  14. pixel = oldBitmap.GetPixel(x, y);
  15. int r, g, b, Result = 0;
  16. r = pixel.R;
  17. g = pixel.G;
  18. b = pixel.B;
  19. //实例程序以加权平均值法发生黑白图像
  20. int iType =2;
  21. switch (iType)
  22. {
  23. case 0://平均值法
  24. Result = ((r + g + b) / 3);
  25. break;
  26. case 一://最大值法
  27. Result = r > g ? r : g;
  28. Result = Result > b ? Result : b;
  29. break;
  30. case 二://加权平均值法
  31. Result = ((int)(0.7 * r) + (int)(0.2 * g) + (int)(0.1 * b));
  32. break;
  33. }
  34. newBitmap.SetPixel(x, y, Color.FromArgb(Result, Result, Result));
  35. }
  36. this.pictureBox1.Image = newBitmap;
  37. }
  38. catch (Exception ex)
  39. {
  40. MessageBox.Show(ex.Message, “新闻提醒”);
  41. }
  42. }

复制代码

四. 柔化效果
规律: 当前像素点与相近像素点的颜料差异较大时取其平均值.
效果图:
附件: 2008092313290866.jpg
代码达成:
柔化效果

  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. //以柔化效果显示图像
  4. try
  5. {
  6. int Height = this.pictureBox1.Image.Height;
  7. int Width = this.pictureBox1.Image.Width;
  8. Bitmap bitmap = new Bitmap(Width, Height);
  9. Bitmap MyBitmap = (Bitmap)this.pictureBox1.Image;
  10. Color pixel;
  11. //高斯模板
  12. int[] Gauss ={ 1, 2, 1, 2, 4, 2, 1, 2, 1 };
  13. for (int x = 1; x < Width – 1; x++)
  14. for (int y = 1; y < Height – 1; y++)
  15. {
  16. int r = 0, g = 0, b = 0;
  17. int Index = 0;
  18. for (int col = -1; col <= 1; col++)
  19. for (int row = -1; row <= 1; row++)
  20. {
  21. pixel = MyBitmap.GetPixel(x + row, y + col);
  22. r += pixel.R * Gauss[Index];
  23. g += pixel.G * Gauss[Index];
  24. b += pixel.B * Gauss[Index];
  25. Index++;
  26. }
  27. r /= 16;
  28. g /= 16;
  29. b /= 16;
  30. //处理颜色值溢出
  31. r = r > 255 ? 255 : r;
  32. r = r < 0 ? 0 : r;
  33. g = g > 255 ? 255 : g;
  34. g = g < 0 ? 0 : g;
  35. b = b > 255 ? 255 : b;
  36. b = b < 0 ? 0 : b;
  37. bitmap.SetPixel(x – 1, y – 1, Color.FromArgb(r, g, b));
  38. }
  39. this.pictureBox1.Image = bitmap;
  40. }
  41. catch (Exception ex)
  42. {
  43. MessageBox.Show(ex.Message, “音讯提醒”);
  44. }
  45. }

复制代码

5.锐化效果
规律:卓绝体现颜色值大(即形成形体边缘)的像素点.
效果图:
附件: 2008092313325828.jpg
落到实处代码:
锐化效果

  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. //以锐化效果彰显图像
  4. try
  5. {
  6. int Height = this.pictureBox1.Image.Height;
  7. int Width = this.pictureBox1.Image.Width;
  8. Bitmap newBitmap = new Bitmap(Width, Height);
  9. Bitmap oldBitmap = (Bitmap)this.pictureBox1.Image;
  10. Color pixel;
  11. //拉普Russ模板
  12. int[] Laplacian ={ -1, -1, -1, -1, 9, -1, -1, -1, -1 };
  13. for (int x = 1; x < Width – 1; x++)
  14. for (int y = 1; y < Height – 1; y++)
  15. {
  16. int r = 0, g = 0, b = 0;
  17. int Index = 0;
  18. for (int col = -1; col <= 1; col++)
  19. for (int row = -1; row <= 1; row++)
  20. {
  21. pixel = oldBitmap.GetPixel(x + row, y + col); r += pixel.R *
    Laplacian[Index];
  22. g += pixel.G * Laplacian[Index];
  23. b += pixel.B * Laplacian[Index];
  24. Index++;
  25. }
  26. //处理颜色值溢出
  27. r = r > 255 ? 255 : r;
  28. r = r < 0 ? 0 : r;
  29. g = g > 255 ? 255 : g;
  30. g = g < 0 ? 0 : g;
  31. b = b > 255 ? 255 : b;
  32. b = b < 0 ? 0 : b;
  33. newBitmap.SetPixel(x – 1, y – 1, Color.FromArgb(r, g, b));
  34. }
  35. this.pictureBox1.Image = newBitmap;
  36. }
  37. catch (Exception ex)
  38. {
  39. MessageBox.Show(ex.Message, “消息提醒”);
  40. }
  41. }

复制代码

6. 雾化效果
规律: 在图像中引入一定的任性值, 打乱图像中的像素值
效果图:
附件: 2008092313371870.jpg
兑现代码:
雾化效果

  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. //以雾化效果突显图像
  4. try
  5. {
  6. int Height = this.pictureBox1.Image.Height;
  7. int Width = this.pictureBox1.Image.Width;
  8. Bitmap newBitmap = new Bitmap(Width, Height);
  9. Bitmap oldBitmap = (Bitmap)this.pictureBox1.Image;
  10. Color pixel;
  11. for (int x = 1; x < Width – 1; x++)
  12. for (int y = 1; y < Height – 1; y++)
  13. {
  14. System.Random MyRandom = new Random();
  15. int k = MyRandom.Next(123456);
  16. //像素块大小
  17. int dx = x + k % 19;
  18. int dy = y + k % 19;
  19. if (dx >= Width)
  20. dx = Width – 1;
  21. if (dy >= Height)
  22. dy = Height – 1;
  23. pixel = oldBitmap.GetPixel(dx, dy);
  24. newBitmap.SetPixel(x, y, pixel);
  25. }
  26. this.pictureBox1.Image = newBitmap;
  27. }
  28. catch (Exception ex)
  29. {
  30. MessageBox.Show(ex.Message, “音讯提醒”);
  31. }
  32. }

复制代码

七. 普照效果
规律: 对图像中的某一限量内的像素的亮度分别展开处理.
效果图:
附件: 2008092313414314.jpg
落到实处代码:
光照效果

  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. //以光照效果展现图像
  4. Graphics MyGraphics = this.pictureBox1.CreateGraphics();
  5. MyGraphics.Clear(Color.White);
  6. Bitmap MyBmp = new Bitmap(this.pictureBox1.Image,
    this.pictureBox1.Width, this.pictureBox1.Height);
  7. int MyWidth = MyBmp.Width;
  8. int MyHeight = MyBmp.Height;
  9. Bitmap MyImage = MyBmp.Clone(new RectangleF(0, 0, MyWidth,
    MyHeight), System.Drawing.Imaging.PixelFormat.DontCare);
  10. int A = Width / 2;
  11. int B = Height / 2;
  12. //MyCenter图片中央点,发亮此值会让光线主题发出偏移
  13. Point MyCenter = new Point(MyWidth / 2, MyHeight / 2);
  14. //锐界强光照射面包车型大巴半径,即”光晕”
  15. int R = Math.Min(MyWidth / 2, MyHeight / 2);
  16. for (int i = MyWidth – 1; i >= 1; i–)
  17. {
  18. for (int j = MyHeight – 1; j >= 1; j–)
  19. {
  20. float MyLength = (float)Math.Sqrt(Math.Pow((i – MyCenter.X), 2) +
    Math.Pow((j – MyCenter.Y), 2));
  21. //假若像素位于”光晕”之内
  22. if (MyLength < R)
  23. {
  24. Color MyColor = MyImage.GetPixel(i, j);
  25. int r, g, b;
  26. //220亮度扩充常量,该值越大,光亮度越强
  27. float MyPixel = 220.0f * (1.0f – MyLength / R);
  28. r = MyColor.R + (int)MyPixel;
  29. r = Math.Max(0, Math.Min(r, 255));
  30. g = MyColor.G + (int)MyPixel;
  31. g = Math.Max(0, Math.Min(g, 255));
  32. b = MyColor.B + (int)MyPixel;
  33. b = Math.Max(0, Math.Min(b, 255));
  34. //将增亮后的像素值回写到位图
  35. Color MyNewColor = Color.FromArgb(255, r, g, b);
  36. MyImage.SetPixel(i, j, MyNewColor);
  37. }
  38. }
  39. //重新绘制图片
  40. MyGraphics.DrawImage(MyImage, new Rectangle(0, 0, MyWidth,
    MyHeight));
  41. }
  42. }
  43. }

复制代码

八.百叶窗效果
规律:(一).垂直百叶窗效果:
依据窗口或图像的惊人或宽度和定制的百叶窗显示条宽度计算百叶窗显示的条数据

依据窗口或图像的莫斯中国科学技术大学学或宽度定制百叶窗展现条数据计算百窗展现的条宽度.
(二).水平百叶窗效果: 原理同上,只是绘制像素点开头的坐标分歧.
效果图:
附件: 2008092314525230.jpg    附件:
2008092314541655.jpg
达成代码:
垂直百叶窗

  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. //垂直百叶窗彰显图像
  4. try
  5. {
  6. MyBitmap = (Bitmap)this.pictureBox1.Image.Clone();
  7. int dw = MyBitmap.Width / 30;
  8. int dh = MyBitmap.Height;
  9. Graphics g = this.pictureBox1.CreateGraphics();
  10. g.Clear(Color.Gray);
  11. Point[] MyPoint = new Point[30];
  12. for (int x = 0; x < 30; x++)
  13. {
  14. MyPoint[x].Y = 0;
  15. MyPoint[x].X = x * dw;
  16. }
  17. 银河至尊游戏官网,Bitmap bitmap = new Bitmap(MyBitmap.Width, MyBitmap.Height);
  18. for (int i = 0; i < dw; i++)
  19. {
  20. for (int j = 0; j < 30; j++)
  21. {
  22. for (int k = 0; k < dh; k++)
  23. {
  24. bitmap.SetPixel(MyPoint[j].X + i, MyPoint[j].Y + k,
  25. MyBitmap.GetPixel(MyPoint[j].X + i, MyPoint[j].Y + k));
  26. }
  27. }
  28. this.pictureBox1.Refresh();
  29. this.pictureBox1.Image = bitmap;
  30. System.Threading.Thread.Sleep(100);
  31. }
  32. }
  33. catch (Exception ex)
  34. {
  35. MessageBox.Show(ex.Message, “音信提示”);
  36. }
  37. }

复制代码

水平百叶窗

  1. private void button3_Click(object sender, EventArgs e)
  2. {
  3. //水平百叶窗呈现图像
  4. try
  5. {
  6. MyBitmap = (Bitmap)this.pictureBox1.Image.Clone();
  7. int dh = MyBitmap.Height / 20;
  8. int dw = MyBitmap.Width;
  9. Graphics g = this.pictureBox1.CreateGraphics();
  10. g.Clear(Color.Gray);
  11. Point[] MyPoint = new Point[20];
  12. for (int y = 0; y < 20; y++)
  13. {
  14. MyPoint[y].X = 0;
  15. MyPoint[y].Y = y * dh;
  16. }
  17. Bitmap bitmap = new Bitmap(MyBitmap.Width, MyBitmap.Height);
  18. for (int i = 0; i < dh; i++)
  19. {
  20. for (int j = 0; j < 20; j++)
  21. {
  22. for (int k = 0; k < dw; k++)
  23. {
  24. bitmap.SetPixel(MyPoint[j].X + k, MyPoint[j].Y + i,
    MyBitmap.GetPixel(MyPoint[j].X + k, MyPoint[j].Y + i));
  25. }
  26. }
  27. this.pictureBox1.Refresh();
  28. this.pictureBox1.Image = bitmap;
  29. System.Threading.Thread.Sleep(100);
  30. }
  31. }
  32. catch (Exception ex)
  33. {
  34. Message博克斯.Show(ex.Message, “新闻提示”);
  35. }
  36. }

复制代码

9.马普托克遵循
规律:
鲜明图像的人身自由地点点和明确布里Stowe克块的大大小小,然后马赛克块图像覆盖随机点即可.
效果图:
附件: 2008092315095126.jpg
实现代码:
斯特拉斯堡克效果

  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. //以博洛尼亚克效果突显图像
  4. try
  5. {
  6. int dw = MyBitmap.Width / 50;
  7. int dh = MyBitmap.Height / 50;
  8. Graphics g = this.pictureBox1.CreateGraphics();
  9. g.Clear(Color.Gray);
  10. Point[] MyPoint = new Point[2500];
  11. for (int x = 0; x < 50; x++)
  12. for (int y = 0; y < 50; y++)
  13. {
  14. MyPoint[x * 50 + y].X = x * dw;
  15. MyPoint[x * 50 + y].Y = y * dh;
  16. }
  17. Bitmap bitmap = new Bitmap(MyBitmap.Width, MyBitmap.Height);
  18. for (int i = 0; i < 10000; i++)
  19. {
  20. System.Random MyRandom = new Random();
  21. int iPos = MyRandom.Next(2500);
  22. for (int m = 0; m < dw; m++)
  23. for (int n = 0; n < dh; n++)
  24. {
  25. bitmap.SetPixel(MyPoint[iPos].X + m, MyPoint[iPos].Y + n,
    MyBitmap.GetPixel(MyPoint[iPos].X + m, MyPoint[iPos].Y + n));
  26. }
  27. this.pictureBox1.Refresh();
  28. this.pictureBox1.Image = bitmap;
  29. }
  30. for (int i = 0; i < 2500; i++)
  31. for (int m = 0; m < dw; m++)
  32. for (int n = 0; n < dh; n++)
  33. {
  34. bitmap.SetPixel(MyPoint[i].X + m, MyPoint[i].Y + n,
    MyBitmap.GetPixel(MyPoint[i].X + m, MyPoint[i].Y + n));
  35. }
  36. this.pictureBox1.Refresh();
  37. this.pictureBox1.Image = bitmap;
  38. }
  39. catch (Exception ex)
  40. {
  41. MessageBox.Show(ex.Message, “新闻提醒”);
  42. }
  43. }

复制代码

10. 雕塑效果
规律: 对图像中某1范围内的像素引入自由值.
效果图:
附件: 2008092315141094.jpg
福寿无疆代码:
水墨画效果

  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. //以雕塑效果突显图像
  4. Graphics g = this.panel1.CreateGraphics();
  5. //Bitmap bitmap = this.MyBitmap;
  6. //取得图片尺寸
  7. int width = MyBitmap.Width;
  8. int height = MyBitmap.Height;
  9. RectangleF rect = new RectangleF(0, 0, width, height);
  10. Bitmap img = MyBitmap.Clone(rect,
    System.Drawing.Imaging.PixelFormat.DontCare);
  11. //产生随机数体系
  12. Random rnd = new Random();
  13. //取不相同的值决定摄影效果的分化水平
  14. int iModel = 2;
  15. int i = width – iModel;
  16. while (i > 1)
  17. {
  18. int j = height – iModel;
  19. while (j > 1)
  20. {
  21. int iPos = rnd.Next(100000) % iModel;
  22. //将该点的索罗德GB值设置成周边iModel点之内的任一点
  23. Color color = img.GetPixel(i + iPos, j + iPos);
  24. img.SetPixel(i, j, color);
  25. j = j – 1;
  26. }
  27. i = i – 1;
  28. }
  29. //重新绘制图像
  30. g.Clear(Color.White);
  31. g.DrawImage(img, new Rectangle(0, 0, width, height));
  32. }

复制代码

10一: 扭曲成效
原理: 将图像缩放为3个非矩形的相同肆边形即可
效果图:
附件: 2008092315191111.jpg
福寿康宁代码:
扭转功用

  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. //以扭曲成效展现图像
  4. if (h == panel1.Height/2)
  5. {
  6. w = 0;
  7. h = 0;
  8. }
  9. Size offset =new Size (w++,h++);//设置偏移量
  10. Graphics g = panel1.CreateGraphics();
  11. Rectangle rect = this.panel1.ClientRectangle;
  12. Point[] points = new Point[3];
  13. points[0] = new Point(rect.Left+offset.Width ,rect.Top +offset
    .Height);
  14. points[1] = new Point(rect.Right, rect.Top + offset.Height);
  15. points[2] = new Point(rect.Left, rect.Bottom – offset.Height);
  16. g.Clear(Color.White);
  17. g.DrawImage(MyBitmap, points);
  18. }

复制代码

拾二.积木效用
规律: 对图像中的各个像素点珍视(即加大分像素的颜色值)着色.
效果图:
附件: 2008092315230292.jpg
金镶玉裹福禄双全代码:
积木效果

  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. //以积木效果展现图像
  4. try
  5. {
  6. Graphics myGraphics = this.panel1.CreateGraphics ();
  7. //Bitmap myBitmap = new Bitmap(this.BackgroundImage);
  8. int myWidth, myHeight, i, j, iAvg, iPixel;
  9. Color myColor, myNewColor;
  10. RectangleF myRect;
  11. myWidth = MyBitmap.Width;
  12. myHeight = MyBitmap.Height;
  13. myRect = new RectangleF(0, 0, myWidth, myHeight);
  14. Bitmap bitmap = MyBitmap.Clone(myRect,
    System.Drawing.Imaging.PixelFormat.DontCare);
  15. i = 0;
  16. while (i < myWidth – 1)
  17. {
  18. j = 0;
  19. while (j < myHeight – 1)
  20. {
  21. myColor = bitmap.GetPixel(i, j);
  22. iAvg = (myColor.R + myColor.G + myColor.B) / 3;
  23. iPixel = 0;
  24. if (iAvg >= 128)
  25. iPixel = 255;
  26. else
  27. iPixel = 0;
  28. myNewColor = Color.FromArgb(255, iPixel, iPixel, iPixel);
  29. bitmap.SetPixel(i, j, myNewColor);
  30. j = j + 1;
  31. }
  32. i = i + 1;
  33. }
  34. myGraphics.Clear(Color.WhiteSmoke);
  35. myGraphics.DrawImage(bitmap, new Rectangle(0, 0, myWidth,
    myHeight));
  36. }
  37. catch (Exception ex)
  38. {
  39. MessageBox.Show(ex.Message, “新闻提醒”);
  40. }
  41. }

复制代码

表明.那一个基本上为静态图. 前边会有图像的动态展现. 如分块合成图像,
四周扩散彰显图像, 上下对接显示图像等.

      那么些只怕能印证一下
PPT恐怕手提式有线电话机中的图片效果处理程序是固然做出来的.原理应该是相通的.

      制作图像相似常用的类有: Bitmap; Graphics; Rectangle;Color;
用到的点子是 Graphics类的DrawImage;
      此办法共有221个版本, 作者习惯用 DrawImage(“图像”, “图框”) 版本.

      因为那些版本的沉思是最简单易行的—-把一张**地图像装在3个**地框里!
(**代表某种意义的图像和某种意义的框)
      如. g.DrawImage(new Bitmap(“myPicture”), new Rectangle(0, 0,
myWidth, myHeight));

      呵呵, 到此
    希望对大家有所帮忙.

来自:http://www.pin5i.com/showtopic-20228.html

相关文章