Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace grafika1
  12. {
  13. public partial class Form1 : Form
  14. {
  15. Bitmap pomoc;
  16. Bitmap obraz, kopia;
  17. public Form1()
  18. {
  19. InitializeComponent();
  20. }
  21.  
  22. private void Negatyw()
  23. {
  24. obraz = new Bitmap(pictureBox1.Image);
  25. kopia = new Bitmap(obraz.Width, obraz.Height);
  26. pictureBox1.Image = obraz;
  27.  
  28. pomoc = new Bitmap(obraz.Width, obraz.Height);
  29. Color punkt;
  30. for (int i = 0; i < obraz.Width; i++)
  31. {
  32. for (int j = 0; j < obraz.Height; j++)
  33. {
  34. punkt = obraz.GetPixel(i, j);
  35. pomoc.SetPixel(i, j, Color.FromArgb(255 - punkt.R, 255 - punkt.G, 255 - punkt.B));
  36. }
  37. }
  38. pictureBox2.Image = pomoc;
  39. }
  40.  
  41. private void button2_Click(object sender, EventArgs e)
  42. {
  43. Negatyw();
  44. }
  45.  
  46. private void button1_Click(object sender, EventArgs e)
  47. {
  48. openFileDialog1.ShowDialog();
  49. }
  50.  
  51. private void button3_Click(object sender, EventArgs e)
  52. {
  53. convertToGrayScale();
  54. }
  55. private void convertToGrayScale()
  56. {
  57. obraz = new Bitmap(pictureBox1.Image);
  58. kopia = new Bitmap(obraz.Width, obraz.Height);
  59. pictureBox1.Image = obraz;
  60.  
  61. pomoc = new Bitmap(obraz.Width, obraz.Height);
  62. Color punkt;
  63.  
  64. for (int i = 0; i < obraz.Width; i++)
  65. {
  66. for (int j = 0; j < obraz.Height; j++)
  67. {
  68.  
  69. punkt = obraz.GetPixel(i, j);
  70. pomoc.SetPixel(i, j, Color.FromArgb((punkt.R+punkt.G+punkt.B)/3,(punkt.R+punkt.G+punkt.B)/3,(punkt.R+punkt.G+punkt.B)/3));
  71.  
  72. }
  73. }
  74. pictureBox2.Image = pomoc;
  75.  
  76. }
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement