Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.00 KB | None | 0 0
  1. private void BtnPixellate_Click(object sender, EventArgs e)
  2. {
  3. if (bitmapImage == null)
  4. return;
  5.  
  6.  
  7. int iWidth = 320;
  8. int iHeight = 240;
  9.  
  10. //Loops through the image with a step pattern of 4, as it is 4x4 pixelation
  11. for (int i = 0; i < iWidth; i = i + 4)
  12. {
  13. for (int j = 0; j < iHeight; j = j + 4)
  14. {
  15. Color col = ImageArray[i, j];
  16.  
  17. //Makes it so that all the pixels in a 4x4 grid, moving left and down, from the pixel are the same colour
  18. ImageArray[i + 1, j] = col;
  19. ImageArray[i + 2, j] = col;
  20. ImageArray[i + 3, j] = col;
  21. ImageArray[i, j + 1] = col;
  22. ImageArray[i, j + 2] = col;
  23. ImageArray[i, j + 3] = col;
  24. ImageArray[i + 1, j + 1] = col;
  25. ImageArray[i + 1, j + 2] = col;
  26. ImageArray[i + 1, j + 3] = col;
  27. ImageArray[i + 2, j + 1] = col;
  28. ImageArray[i + 2, j + 2] = col;
  29. ImageArray[i + 2, j + 3] = col;
  30. ImageArray[i + 3, j + 1] = col;
  31. ImageArray[i + 3, j + 2] = col;
  32. ImageArray[i + 3, j + 3] = col;
  33.  
  34. }
  35. }
  36. SetBitmapFromAray();
  37. picImage.Image = bitmapImage;
  38. }
  39.  
  40. private void BtnVScroll_Click(object sender, EventArgs e)
  41. {
  42. if (bitmapImage == null)
  43. return;
  44.  
  45.  
  46. int iWidth = 320;
  47. int iHeight = 240;
  48. //Scrolls 40 pixels at a time
  49. int iScroll = 40;
  50. Color[,] TempArray = new Color[iWidth, iHeight];
  51.  
  52. //Loops through the entire image, copying it into a temporary array
  53. for (int i = 0; i < iWidth; i++)
  54. {
  55. for (int j = 0; j < iHeight; j++)
  56. {
  57. Color col = ImageArray[i, j];
  58. TempArray[i, j] = col;
  59. }
  60. }
  61.  
  62. for (int i = 0; i < iWidth; i++)
  63. {
  64. for (int j = 0; j < iHeight; j++)
  65. {
  66. //If the j value is less than 40, it moves a 320x40 section from the bottom to the top
  67. if (j < iScroll)
  68. {
  69. ImageArray[i, iHeight - iScroll + j] = TempArray[i, j];
  70. }
  71. //If the j value is less than 200, it moves a 320x40 section from the top to the bottom
  72. if (j < iHeight - iScroll)
  73. {
  74. ImageArray[i, j] = TempArray[i, j + iScroll];
  75. }
  76. }
  77. }
  78.  
  79. SetBitmapFromAray();
  80. picImage.Image = bitmapImage;
  81. }
  82.  
  83. private void BtnBlur_Click(object sender, EventArgs e)
  84. {
  85. if (bitmapImage == null)
  86. return;
  87.  
  88.  
  89. int Red, Green, Blue;
  90. int iWidth = 320;
  91. int iHeight = 240;
  92. Color[,] TempArray = new Color[iWidth, iHeight];
  93.  
  94. //Loops through the entire image, copying it into a temporary array
  95. for (int i = 0; i < iWidth; i++)
  96. {
  97. for (int j = 0; j < iHeight; j++)
  98. {
  99. Color col = ImageArray[i, j];
  100. TempArray[i, j] = col;
  101. }
  102. }
  103.  
  104. for (int i = 0; i < iWidth; i++)
  105. {
  106. for (int j = 0; j < iHeight; j++)
  107. {
  108. Color col = TempArray[i, j];
  109. Red = col.R;
  110. Green = col.G;
  111. Blue = col.B;
  112. //Sets each element in a pixel to the average of those around it, based upon its location in the array
  113. //Top Left
  114. if (i == 0 && j == 0)
  115. {
  116. Red = (TempArray[i, j].R + TempArray[i + 1, j].R + TempArray[i, j + 1].R + TempArray[i + 1, j + 1].R) / 4;
  117. Green = (TempArray[i, j].G + TempArray[i + 1, j].G + TempArray[i, j + 1].G + TempArray[i + 1, j + 1].G) / 4;
  118. Blue = (TempArray[i, j].B + TempArray[i + 1, j].B + TempArray[i, j + 1].B + TempArray[i + 1, j + 1].B) / 4;
  119. }
  120. //Top Right
  121. else if (i == (iWidth - 1) && j == 0)
  122. {
  123. Red = (TempArray[i, j].R + TempArray[i - 1, j].R + TempArray[i, j + 1].R + TempArray[i - 1, j + 1].R) / 4;
  124. Green = (TempArray[i, j].G + TempArray[i - 1, j].G + TempArray[i, j + 1].G + TempArray[i - 1, j + 1].G) / 4;
  125. Blue = (TempArray[i, j].B + TempArray[i - 1, j].B + TempArray[i, j + 1].B + TempArray[i - 1, j + 1].B) / 4;
  126. }
  127. //Bottom Right
  128. else if (i == (iWidth - 1) && j == (iHeight - 1))
  129. {
  130. Red = (TempArray[i, j].R + TempArray[i - 1, j].R + TempArray[i, j - 1].R + TempArray[i - 1, j - 1].R) / 4;
  131. Green = (TempArray[i, j].G + TempArray[i - 1, j].G + TempArray[i, j - 1].G + TempArray[i - 1, j - 1].G) / 4;
  132. Blue = (TempArray[i, j].B + TempArray[i - 1, j].B + TempArray[i, j - 1].B + TempArray[i - 1, j - 1].B) / 4;
  133. }
  134. //Bottom Left
  135. else if (i == 0 && j == (iHeight - 1))
  136. {
  137. Red = (TempArray[i, j].R + TempArray[i + 1, j].R + TempArray[i, j - 1].R + TempArray[i + 1, j - 1].R) / 4;
  138. Green = (TempArray[i, j].G + TempArray[i + 1, j].G + TempArray[i, j - 1].G + TempArray[i + 1, j - 1].G) / 4;
  139. Blue = (TempArray[i, j].B + TempArray[i + 1, j].B + TempArray[i, j - 1].B + TempArray[i + 1, j - 1].B) / 4;
  140. }
  141. //Left Edge
  142. else if (i == 0)
  143. {
  144. Red = (TempArray[i, j].R + TempArray[i, j - 1].R + TempArray[i + 1, j - 1].R + TempArray[i + 1, j].R + TempArray[i, j + 1].R + TempArray[i + 1, j + 1].R) / 6;
  145. Green = (TempArray[i, j].G + TempArray[i, j - 1].G + TempArray[i + 1, j - 1].G + TempArray[i + 1, j].G + TempArray[i, j + 1].G + TempArray[i + 1, j + 1].G) / 6;
  146. Blue = (TempArray[i, j].B + TempArray[i, j - 1].B + TempArray[i + 1, j - 1].B + TempArray[i + 1, j].B + TempArray[i, j + 1].B + TempArray[i + 1, j + 1].B) / 6;
  147.  
  148. }
  149. //Top Row
  150. else if (j == 0)
  151. {
  152. Red = (TempArray[i, j].R + TempArray[i - 1, j].R + TempArray[i + 1, j].R + TempArray[i - 1, j + 1].R + TempArray[i, j + 1].R + TempArray[i + 1, j + 1].R) / 6;
  153. Green = (TempArray[i, j].G + TempArray[i - 1, j].G + TempArray[i + 1, j].G + TempArray[i - 1, j + 1].G + TempArray[i, j + 1].G + TempArray[i + 1, j + 1].G) / 6;
  154. Blue = (TempArray[i, j].B + TempArray[i - 1, j].B + TempArray[i + 1, j].B + TempArray[i - 1, j + 1].B + TempArray[i, j + 1].B + TempArray[i + 1, j + 1].B) / 6;
  155.  
  156. }
  157. //Right Edge
  158. else if (i == (iWidth - 1))
  159. {
  160. Red = (TempArray[i, j].R + TempArray[i - 1, j - 1].R + TempArray[i, j - 1].R + TempArray[i - 1, j].R + TempArray[i - 1, j + 1].R + TempArray[i, j + 1].R) / 6;
  161. Green = (TempArray[i, j].G + TempArray[i - 1, j - 1].G + TempArray[i, j - 1].G + TempArray[i - 1, j].G + TempArray[i - 1, j + 1].G + TempArray[i, j + 1].G) / 6;
  162. Blue = (TempArray[i, j].B + TempArray[i - 1, j - 1].B + TempArray[i, j - 1].B + TempArray[i - 1, j].B + TempArray[i - 1, j + 1].B + TempArray[i, j + 1].B) / 6;
  163.  
  164. }
  165. //Bottom Row
  166. else if (j == iHeight - 1)
  167. {
  168. Red = (TempArray[i, j].R + TempArray[i - 1, j - 1].R + TempArray[i, j - 1].R + TempArray[i + 1, j - 1].R + TempArray[i - 1, j].R + TempArray[i + 1, j].R) / 6;
  169. Green = (TempArray[i, j].G + TempArray[i - 1, j - 1].G + TempArray[i, j - 1].G + TempArray[i + 1, j - 1].G + TempArray[i - 1, j].G + TempArray[i + 1, j].G) / 6;
  170. Blue = (TempArray[i, j].B + TempArray[i - 1, j - 1].B + TempArray[i, j - 1].B + TempArray[i + 1, j - 1].B + TempArray[i - 1, j].B + TempArray[i + 1, j].B) / 6;
  171.  
  172. }
  173. else
  174. {
  175. Red = (TempArray[i, j].R + TempArray[i - 1, j - 1].R + TempArray[i, j - 1].R + TempArray[i + 1, j - 1].R + TempArray[i - 1, j].R + TempArray[i + 1, j].R + TempArray[i - 1, j + 1].R + TempArray[i, j + 1].R + TempArray[i + 1, j + 1].R) / 9;
  176. Green = (TempArray[i, j].G + TempArray[i - 1, j - 1].G + TempArray[i, j - 1].G + TempArray[i + 1, j - 1].G + TempArray[i - 1, j].G + TempArray[i + 1, j].G + TempArray[i - 1, j + 1].G + TempArray[i, j + 1].G + TempArray[i + 1, j + 1].G) / 9;
  177. Blue = (TempArray[i, j].B + TempArray[i - 1, j - 1].B + TempArray[i, j - 1].B + TempArray[i + 1, j - 1].B + TempArray[i - 1, j].B + TempArray[i + 1, j].B + TempArray[i - 1, j + 1].B + TempArray[i, j + 1].B + TempArray[i + 1, j + 1].B) / 9;
  178.  
  179. }
  180. Color newColor = Color.FromArgb(255, Red, Green, Blue);
  181. ImageArray[i, j] = newColor;
  182. }
  183. }
  184.  
  185. SetBitmapFromAray();
  186. picImage.Image = bitmapImage;
  187. }
  188.  
  189. private void BtnSort_Click(object sender, EventArgs e)
  190. {
  191. if (bitmapImage == null)
  192. return;
  193.  
  194. int iWidth = 320;
  195. int iHeight = 240;
  196. int iValue, iCurrent;
  197. int Red, Green, Blue;
  198.  
  199. for (int j = 0; j < iHeight; j++)
  200. {
  201. for (int i = 0; i < iWidth; i++)
  202. {
  203. Color col = ImageArray[i, j];
  204.  
  205. //iValue is the average RGB value of the pixel in the current spot in the loop
  206. iValue = (ImageArray[i, j].R + ImageArray[i, j].G + ImageArray[i, j].B) / 3;
  207. //int k is the x value of the pixel behind the current spot in the loop
  208. int k = i - 1;
  209. while (k >= 0)
  210. {
  211. //iCurrent is the average RGB value of the pixel behind the current spot in the loop
  212. iCurrent = (ImageArray[k, j].R + ImageArray[k, j].G + ImageArray[k, j].B) / 3;
  213. //If the previous pixel value is greater than the current one they switch spots
  214. if (iCurrent > iValue)
  215. {
  216. ImageArray[k + 1, j] = ImageArray[k, j];
  217. }
  218. else
  219. {
  220. break;
  221. }
  222. k--;
  223. }
  224.  
  225. Red = iValue;
  226. Green = iValue;
  227. Blue = iValue;
  228. Color newColor = Color.FromArgb(255, Red, Green, Blue);
  229. ImageArray[k + 1, j] = newColor;
  230. }
  231. }
  232.  
  233. SetBitmapFromAray();
  234. picImage.Image = bitmapImage;
  235. }
  236.  
  237. private void PicImage_MouseClick(object sender, MouseEventArgs e)
  238. {
  239. if (bitmapImage == null)
  240. return;
  241.  
  242.  
  243. int iWidth = 320;
  244. int iHeight = 240;
  245. Color[,] ZoomArray = new Color[160, 120];
  246.  
  247. //Loops through the area of the array that is being zoomed into and stores it in a temporary array
  248. for (int i = 0; i < (iWidth / 2); i++)
  249. {
  250. for (int j = 0; j < (iHeight / 2); j++)
  251. {
  252. Color col = ImageArray[i + 79, j + 59];
  253. ZoomArray[i, j] = col;
  254. }
  255. }
  256.  
  257. //Loops through half of the array, as it is 2x zoom
  258. for (int i = 0; i < (iWidth / 2); i++)
  259. {
  260.  
  261. for (int j = 0; j < (iHeight / 2); j++)
  262. {
  263.  
  264. Color col = ZoomArray[i, j];
  265.  
  266. //i and j are multiplied by 2 to cover all of ImageArray
  267. ImageArray[2 * i, 2 * j] = col;
  268. ImageArray[2 * i + 1, 2 * j] = col;
  269. ImageArray[2 * i, 2 * j + 1] = col;
  270. ImageArray[2 * i + 1, 2 * j + 1] = col;
  271.  
  272. }
  273.  
  274. }
  275. SetBitmapFromAray();
  276. picImage.Image = bitmapImage;
  277.  
  278.  
  279. }
  280. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement