Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.59 KB | None | 0 0
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. using System.Drawing.Imaging;
  5. using System.IO;
  6.  
  7. namespace PhotoEditor
  8. {
  9. public partial class Form1 : Form
  10. {
  11. Bitmap bmp = null;
  12.  
  13.  
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. }
  18.  
  19. System.Drawing.Image file;
  20. Boolean opened = false;
  21.  
  22.  
  23. private void button1_Click(object sender, EventArgs e)
  24. {
  25. OpenFileDialog ofd = new OpenFileDialog();
  26. if (ofd.ShowDialog().Equals(DialogResult.OK))
  27. {
  28. string fname = ofd.FileName;
  29.  
  30. bmp = (Bitmap)Bitmap.FromFile(fname);
  31. Bitmap b2 = new Bitmap(bmp, pictureBox1.Size);
  32. pictureBox1.Image = b2;
  33. }
  34. }
  35.  
  36. private void trackBar1_Scroll(object sender, EventArgs e)
  37. {
  38. float changeb = trackBar1.Value * 0.1f;
  39.  
  40. trackBar1.Text = changeb.ToString();
  41.  
  42. System.Drawing.Image img = pictureBox1.Image; // storing image into img variable of image type from picturebox1
  43. Bitmap bmpInverted = new Bitmap(img.Width, img.Height); /* creating a bitmap of the height of imported picture in picturebox which consists of the pixel data for a graphics image
  44. and its attributes. A Bitmap is an object used to work with images defined by pixel data.*/
  45.  
  46. ImageAttributes ia = new ImageAttributes(); //creating an object of imageattribute ia to change the attribute of images
  47. ColorMatrix cmPicture = new ColorMatrix(new float[][] // now creating the color matrix object to change the colors or apply image filter on image
  48. {
  49. new float[]{1, 0, 0, 0, 0},
  50. new float[]{0, 1, 0, 0, 0},
  51. new float[]{0, 0, 1, 0, 0},
  52. new float[]{0, 0, 0, 1, 0},
  53. new float[]{0+changeb, 0+changeb, 0+changeb, 0, 1}
  54. });
  55. ia.SetColorMatrix(cmPicture); //pass the color matrix to imageattribute object ia
  56. Graphics g = Graphics.FromImage(bmpInverted); /*create a new object of graphics named g, ; Create graphics object for alteration.
  57. Graphics newGraphics = Graphics.FromImage(imageFile); is the format of loading image into graphics for alteration*/
  58.  
  59. g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);
  60.  
  61.  
  62. /* g.drawimage(image, new rectangle(location of rectangle axix-x, location axis-y, width of rectangle, height of rectangle),
  63. location of image in rectangle x-axis, location of image in rectangle y-axis, width of image, height of image,
  64. format of graphics unit,provide the image attributes */
  65.  
  66.  
  67. g.Dispose(); //Releases all resources used by this Graphics.
  68. pictureBox1.Image = bmpInverted;
  69.  
  70.  
  71. }
  72.  
  73. private void pictureBox1_Click(object sender, EventArgs e)
  74. {
  75.  
  76. }
  77.  
  78. private void button2_Click(object sender, EventArgs e)
  79. {
  80. Image img = pictureBox1.Image; // storing image into img variable of image type from picturebox1
  81. Bitmap bmpInverted = new Bitmap(img.Width, img.Height); /* creating a bitmap of the height of imported picture in picturebox which consists of the pixel data for a graphics image
  82. and its attributes. A Bitmap is an object used to work with images defined by pixel data.*/
  83.  
  84. ImageAttributes ia = new ImageAttributes(); //creating an object of imageattribute ia to change the attribute of images
  85. ColorMatrix cmPicture = new ColorMatrix(new float[][] // now creating the color matrix object to change the colors or apply image filter on image
  86. {
  87. new float[]{0.393f, 0.349f, 0.272f, 0, 0},
  88. new float[]{0.769f, 0.686f, 0.534f, 0, 0},
  89. new float[]{.189f, .168f, .131f, 0, 0},
  90. new float[]{0, 0, 0, 1, 0},
  91. new float[]{0, 0, 0, 0, 1}
  92. });
  93. ia.SetColorMatrix(cmPicture); //pass the color matrix to imageattribute object ia
  94. Graphics g = Graphics.FromImage(bmpInverted); /*create a new object of graphics named g, ; Create graphics object for alteration.
  95. Graphics newGraphics = Graphics.FromImage(imageFile); is the format of loading image into graphics for alteration*/
  96.  
  97. g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);
  98.  
  99.  
  100. /* g.drawimage(image, new rectangle(location of rectangle axix-x, location axis-y, width of rectangle, height of rectangle),
  101. location of image in rectangle x-axis, location of image in rectangle y-axis, width of image, height of image,
  102. format of graphics unit,provide the image attributes */
  103.  
  104.  
  105. g.Dispose(); //Releases all resources used by this Graphics.
  106. pictureBox1.Image = bmpInverted;
  107.  
  108. }
  109.  
  110. private void button3_Click(object sender, EventArgs e)
  111. {
  112. System.Drawing.Image img = pictureBox1.Image; // storing image into img variable of image type from picturebox1
  113. Bitmap bmpInverted = new Bitmap(img.Width, img.Height); /* creating a bitmap of the height of imported picture in picturebox which consists of the pixel data for a graphics image
  114. and its attributes. A Bitmap is an object used to work with images defined by pixel data.*/
  115.  
  116. ImageAttributes ia = new ImageAttributes(); //creating an object of imageattribute ia to change the attribute of images
  117. ColorMatrix cmPicture = new ColorMatrix(new float[][] // now creating the color matrix object to change the colors or apply image filter on image
  118. {
  119. new float[]{1.5f, 1.5f, 1.5f, 0, 0},
  120. new float[]{1.5f, 1.5f, 1.5f, 0, 0},
  121. new float[]{1.5f, 1.5f, 1.5f, 0, 0},
  122. new float[]{0, 0, 0, 1, 0},
  123. new float[]{-1, -1, -1, 0, 1}
  124. });
  125. ia.SetColorMatrix(cmPicture); //pass the color matrix to imageattribute object ia
  126. Graphics g = Graphics.FromImage(bmpInverted); /*create a new object of graphics named g, ; Create graphics object for alteration.
  127. Graphics newGraphics = Graphics.FromImage(imageFile); is the format of loading image into graphics for alteration*/
  128.  
  129. g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);
  130.  
  131.  
  132. /* g.drawimage(image, new rectangle(location of rectangle axix-x, location axis-y, width of rectangle, height of rectangle),
  133. location of image in rectangle x-axis, location of image in rectangle y-axis, width of image, height of image,
  134. format of graphics unit,provide the image attributes */
  135.  
  136.  
  137. g.Dispose(); //Releases all resources used by this Graphics.
  138. pictureBox1.Image = bmpInverted;
  139.  
  140. }
  141.  
  142. private void trackBar2_Scroll(object sender, EventArgs e)
  143. {
  144.  
  145. float changec = trackBar2.Value * 0.1f;
  146.  
  147. float t = 0;
  148.  
  149. trackBar2.Text = changec.ToString();
  150.  
  151. System.Drawing.Image img = pictureBox1.Image; // storing image into img variable of image type from picturebox1
  152. Bitmap bmpInverted = new Bitmap(img.Width, img.Height); /* creating a bitmap of the height of imported picture in picturebox which consists of the pixel data for a graphics image
  153. and its attributes. A Bitmap is an object used to work with images defined by pixel data.*/
  154.  
  155. ImageAttributes ia = new ImageAttributes(); //creating an object of imageattribute ia to change the attribute of images
  156. ColorMatrix cmPicture = new ColorMatrix(new float[][] // now creating the color matrix object to change the colors or apply image filter on image
  157. {
  158. new float[]{1+changec, 0, 0, 0, 0},
  159. new float[]{0, 1+changec, 0, 0, 0},
  160. new float[]{0, 0, 1+changec, 0, 0},
  161. new float[]{0, 0, 0, 1, 0},
  162. new float[]{t, t, t, 0, 1}
  163. });
  164.  
  165. if (changec == 0)
  166. t = (1f - changec) / 2f;
  167.  
  168. ia.SetColorMatrix(cmPicture); //pass the color matrix to imageattribute object ia
  169. Graphics g = Graphics.FromImage(bmpInverted); /*create a new object of graphics named g, ; Create graphics object for alteration.
  170. Graphics newGraphics = Graphics.FromImage(imageFile); is the format of loading image into graphics for alteration*/
  171.  
  172. g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);
  173.  
  174.  
  175. /* g.drawimage(image, new rectangle(location of rectangle axix-x, location axis-y, width of rectangle, height of rectangle),
  176. location of image in rectangle x-axis, location of image in rectangle y-axis, width of image, height of image,
  177. format of graphics unit,provide the image attributes */
  178.  
  179.  
  180. g.Dispose(); //Releases all resources used by this Graphics.
  181. pictureBox1.Image = bmpInverted;
  182.  
  183.  
  184. }
  185.  
  186. private void button4_Click(object sender, EventArgs e)
  187. {
  188.  
  189. }
  190.  
  191. private void button5_Click(object sender, EventArgs e)
  192. {
  193. System.Drawing.Image img = pictureBox1.Image; // storing image into img variable of image type from picturebox1
  194. Bitmap bmpInverted = new Bitmap(img.Width, img.Height); /* creating a bitmap of the height of imported picture in picturebox which consists of the pixel data for a graphics image
  195. and its attributes. A Bitmap is an object used to work with images defined by pixel data.*/
  196.  
  197. ImageAttributes ia = new ImageAttributes(); //creating an object of imageattribute ia to change the attribute of images
  198. ColorMatrix cmPicture = new ColorMatrix(new float[][] // now creating the color matrix object to change the colors or apply image filter on image
  199. {
  200. new float[]{-1, 0, 0, 0, 1.00f},
  201. new float[]{0, -1, 0, 0, 1.00f},
  202. new float[]{0, 0, -1, 0, 1.00f},
  203. new float[]{0, 0, 0, 1, 0},
  204. new float[]{1, 1, 1, 0, 1}
  205. });
  206. ia.SetColorMatrix(cmPicture); //pass the color matrix to imageattribute object ia
  207. Graphics g = Graphics.FromImage(bmpInverted); /*create a new object of graphics named g, ; Create graphics object for alteration.
  208. Graphics newGraphics = Graphics.FromImage(imageFile); is the format of loading image into graphics for alteration*/
  209.  
  210. g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);
  211.  
  212.  
  213. /* g.drawimage(image, new rectangle(location of rectangle axix-x, location axis-y, width of rectangle, height of rectangle),
  214. location of image in rectangle x-axis, location of image in rectangle y-axis, width of image, height of image,
  215. format of graphics unit,provide the image attributes */
  216.  
  217.  
  218. g.Dispose(); //Releases all resources used by this Graphics.
  219. pictureBox1.Image = bmpInverted;
  220. }
  221.  
  222. private void button6_Click(object sender, EventArgs e)
  223. {
  224. SaveFileDialog sfd = new SaveFileDialog();
  225.  
  226. sfd.Filter = "Images|*.png;*.bmp;*.jpg";
  227. ImageFormat format = ImageFormat.Png;
  228.  
  229. if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  230. {
  231. string ext = Path.GetExtension(sfd.FileName);
  232.  
  233. switch (ext)
  234. {
  235. case ".jpg":
  236. format = ImageFormat.Jpeg;
  237. break;
  238.  
  239. case ".bmp":
  240. format = ImageFormat.Bmp;
  241. break;
  242. }
  243.  
  244. pictureBox1.Image.Save(sfd.FileName, format);
  245. }
  246. }
  247.  
  248. private void button7_Click(object sender, EventArgs e)
  249. {
  250. System.Drawing.Image img = pictureBox1.Image; // storing image into img variable of image type from picturebox1
  251. Bitmap bmpInverted = new Bitmap(img.Width, img.Height); /* creating a bitmap of the height of imported picture in picturebox which consists of the pixel data for a graphics image
  252. and its attributes. A Bitmap is an object used to work with images defined by pixel data.*/
  253.  
  254. ImageAttributes ia = new ImageAttributes(); //creating an object of imageattribute ia to change the attribute of images
  255. ColorMatrix cmPicture = new ColorMatrix(new float[][] // now creating the color matrix object to change the colors or apply image filter on image
  256. {
  257. new float[]{1.438f, -0.062f, -0.062f, 0, 0},
  258. new float[]{-0.122f, 1.378f, -0.122f, 0, 0},
  259. new float[]{-0.016f, -0.016f, 1.483f, 0, 0},
  260. new float[]{0, 0, 0, 1, 0},
  261. new float[]{-0.03f, 0.05f, -0.02f, 0, 1}
  262. });
  263. ia.SetColorMatrix(cmPicture); //pass the color matrix to imageattribute object ia
  264. Graphics g = Graphics.FromImage(bmpInverted); /*create a new object of graphics named g, ; Create graphics object for alteration.
  265. Graphics newGraphics = Graphics.FromImage(imageFile); is the format of loading image into graphics for alteration*/
  266.  
  267. g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);
  268.  
  269.  
  270. /* g.drawimage(image, new rectangle(location of rectangle axix-x, location axis-y, width of rectangle, height of rectangle),
  271. location of image in rectangle x-axis, location of image in rectangle y-axis, width of image, height of image,
  272. format of graphics unit,provide the image attributes */
  273.  
  274.  
  275. g.Dispose(); //Releases all resources used by this Graphics.
  276. pictureBox1.Image = bmpInverted;
  277. }
  278.  
  279. private void button8_Click(object sender, EventArgs e)
  280. {
  281. System.Drawing.Image img = pictureBox1.Image; // storing image into img variable of image type from picturebox1
  282. Bitmap bmpInverted = new Bitmap(img.Width, img.Height); /* creating a bitmap of the height of imported picture in picturebox which consists of the pixel data for a graphics image
  283. and its attributes. A Bitmap is an object used to work with images defined by pixel data.*/
  284.  
  285. ImageAttributes ia = new ImageAttributes(); //creating an object of imageattribute ia to change the attribute of images
  286. ColorMatrix cmPicture = new ColorMatrix(new float[][] // now creating the color matrix object to change the colors or apply image filter on image
  287. {
  288. new float[]{1, 4, 7, 4, 1},
  289. new float[]{4, 16, 26, 16, 4},
  290. new float[]{7, 26, 41, 26, 7},
  291. new float[]{4, 26, 16, 26, 4},
  292. new float[]{1, 4, 7, 4, 1}
  293. });
  294. ia.SetColorMatrix(cmPicture); //pass the color matrix to imageattribute object ia
  295. Graphics g = Graphics.FromImage(bmpInverted); /*create a new object of graphics named g, ; Create graphics object for alteration.
  296. Graphics newGraphics = Graphics.FromImage(imageFile); is the format of loading image into graphics for alteration*/
  297.  
  298. g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);
  299.  
  300.  
  301. /* g.drawimage(image, new rectangle(location of rectangle axix-x, location axis-y, width of rectangle, height of rectangle),
  302. location of image in rectangle x-axis, location of image in rectangle y-axis, width of image, height of image,
  303. format of graphics unit,provide the image attributes */
  304.  
  305.  
  306. g.Dispose(); //Releases all resources used by this Graphics.
  307. pictureBox1.Image = bmpInverted;
  308. }
  309. }
  310. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement