Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void BtnPixellate_Click(object sender, EventArgs e)
- {
- if (bitmapImage == null)
- return;
- int iWidth = 320;
- int iHeight = 240;
- //Loops through the image with a step pattern of 4, as it is 4x4 pixelation
- for (int i = 0; i < iWidth; i = i + 4)
- {
- for (int j = 0; j < iHeight; j = j + 4)
- {
- Color col = ImageArray[i, j];
- //Makes it so that all the pixels in a 4x4 grid, moving left and down, from the pixel are the same colour
- ImageArray[i + 1, j] = col;
- ImageArray[i + 2, j] = col;
- ImageArray[i + 3, j] = col;
- ImageArray[i, j + 1] = col;
- ImageArray[i, j + 2] = col;
- ImageArray[i, j + 3] = col;
- ImageArray[i + 1, j + 1] = col;
- ImageArray[i + 1, j + 2] = col;
- ImageArray[i + 1, j + 3] = col;
- ImageArray[i + 2, j + 1] = col;
- ImageArray[i + 2, j + 2] = col;
- ImageArray[i + 2, j + 3] = col;
- ImageArray[i + 3, j + 1] = col;
- ImageArray[i + 3, j + 2] = col;
- ImageArray[i + 3, j + 3] = col;
- }
- }
- SetBitmapFromAray();
- picImage.Image = bitmapImage;
- }
- private void BtnVScroll_Click(object sender, EventArgs e)
- {
- if (bitmapImage == null)
- return;
- int iWidth = 320;
- int iHeight = 240;
- //Scrolls 40 pixels at a time
- int iScroll = 40;
- Color[,] TempArray = new Color[iWidth, iHeight];
- //Loops through the entire image, copying it into a temporary array
- for (int i = 0; i < iWidth; i++)
- {
- for (int j = 0; j < iHeight; j++)
- {
- Color col = ImageArray[i, j];
- TempArray[i, j] = col;
- }
- }
- for (int i = 0; i < iWidth; i++)
- {
- for (int j = 0; j < iHeight; j++)
- {
- //If the j value is less than 40, it moves a 320x40 section from the bottom to the top
- if (j < iScroll)
- {
- ImageArray[i, iHeight - iScroll + j] = TempArray[i, j];
- }
- //If the j value is less than 200, it moves a 320x40 section from the top to the bottom
- if (j < iHeight - iScroll)
- {
- ImageArray[i, j] = TempArray[i, j + iScroll];
- }
- }
- }
- SetBitmapFromAray();
- picImage.Image = bitmapImage;
- }
- private void BtnBlur_Click(object sender, EventArgs e)
- {
- if (bitmapImage == null)
- return;
- int Red, Green, Blue;
- int iWidth = 320;
- int iHeight = 240;
- Color[,] TempArray = new Color[iWidth, iHeight];
- //Loops through the entire image, copying it into a temporary array
- for (int i = 0; i < iWidth; i++)
- {
- for (int j = 0; j < iHeight; j++)
- {
- Color col = ImageArray[i, j];
- TempArray[i, j] = col;
- }
- }
- for (int i = 0; i < iWidth; i++)
- {
- for (int j = 0; j < iHeight; j++)
- {
- Color col = TempArray[i, j];
- Red = col.R;
- Green = col.G;
- Blue = col.B;
- //Sets each element in a pixel to the average of those around it, based upon its location in the array
- //Top Left
- if (i == 0 && j == 0)
- {
- Red = (TempArray[i, j].R + TempArray[i + 1, j].R + TempArray[i, j + 1].R + TempArray[i + 1, j + 1].R) / 4;
- Green = (TempArray[i, j].G + TempArray[i + 1, j].G + TempArray[i, j + 1].G + TempArray[i + 1, j + 1].G) / 4;
- Blue = (TempArray[i, j].B + TempArray[i + 1, j].B + TempArray[i, j + 1].B + TempArray[i + 1, j + 1].B) / 4;
- }
- //Top Right
- else if (i == (iWidth - 1) && j == 0)
- {
- Red = (TempArray[i, j].R + TempArray[i - 1, j].R + TempArray[i, j + 1].R + TempArray[i - 1, j + 1].R) / 4;
- Green = (TempArray[i, j].G + TempArray[i - 1, j].G + TempArray[i, j + 1].G + TempArray[i - 1, j + 1].G) / 4;
- Blue = (TempArray[i, j].B + TempArray[i - 1, j].B + TempArray[i, j + 1].B + TempArray[i - 1, j + 1].B) / 4;
- }
- //Bottom Right
- else if (i == (iWidth - 1) && j == (iHeight - 1))
- {
- Red = (TempArray[i, j].R + TempArray[i - 1, j].R + TempArray[i, j - 1].R + TempArray[i - 1, j - 1].R) / 4;
- Green = (TempArray[i, j].G + TempArray[i - 1, j].G + TempArray[i, j - 1].G + TempArray[i - 1, j - 1].G) / 4;
- Blue = (TempArray[i, j].B + TempArray[i - 1, j].B + TempArray[i, j - 1].B + TempArray[i - 1, j - 1].B) / 4;
- }
- //Bottom Left
- else if (i == 0 && j == (iHeight - 1))
- {
- Red = (TempArray[i, j].R + TempArray[i + 1, j].R + TempArray[i, j - 1].R + TempArray[i + 1, j - 1].R) / 4;
- Green = (TempArray[i, j].G + TempArray[i + 1, j].G + TempArray[i, j - 1].G + TempArray[i + 1, j - 1].G) / 4;
- Blue = (TempArray[i, j].B + TempArray[i + 1, j].B + TempArray[i, j - 1].B + TempArray[i + 1, j - 1].B) / 4;
- }
- //Left Edge
- else if (i == 0)
- {
- 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;
- 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;
- 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;
- }
- //Top Row
- else if (j == 0)
- {
- 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;
- 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;
- 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;
- }
- //Right Edge
- else if (i == (iWidth - 1))
- {
- 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;
- 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;
- 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;
- }
- //Bottom Row
- else if (j == iHeight - 1)
- {
- 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;
- 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;
- 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;
- }
- else
- {
- 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;
- 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;
- 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;
- }
- Color newColor = Color.FromArgb(255, Red, Green, Blue);
- ImageArray[i, j] = newColor;
- }
- }
- SetBitmapFromAray();
- picImage.Image = bitmapImage;
- }
- private void BtnSort_Click(object sender, EventArgs e)
- {
- if (bitmapImage == null)
- return;
- int iWidth = 320;
- int iHeight = 240;
- int iValue, iCurrent;
- int Red, Green, Blue;
- for (int j = 0; j < iHeight; j++)
- {
- for (int i = 0; i < iWidth; i++)
- {
- Color col = ImageArray[i, j];
- //iValue is the average RGB value of the pixel in the current spot in the loop
- iValue = (ImageArray[i, j].R + ImageArray[i, j].G + ImageArray[i, j].B) / 3;
- //int k is the x value of the pixel behind the current spot in the loop
- int k = i - 1;
- while (k >= 0)
- {
- //iCurrent is the average RGB value of the pixel behind the current spot in the loop
- iCurrent = (ImageArray[k, j].R + ImageArray[k, j].G + ImageArray[k, j].B) / 3;
- //If the previous pixel value is greater than the current one they switch spots
- if (iCurrent > iValue)
- {
- ImageArray[k + 1, j] = ImageArray[k, j];
- }
- else
- {
- break;
- }
- k--;
- }
- Red = iValue;
- Green = iValue;
- Blue = iValue;
- Color newColor = Color.FromArgb(255, Red, Green, Blue);
- ImageArray[k + 1, j] = newColor;
- }
- }
- SetBitmapFromAray();
- picImage.Image = bitmapImage;
- }
- private void PicImage_MouseClick(object sender, MouseEventArgs e)
- {
- if (bitmapImage == null)
- return;
- int iWidth = 320;
- int iHeight = 240;
- Color[,] ZoomArray = new Color[160, 120];
- //Loops through the area of the array that is being zoomed into and stores it in a temporary array
- for (int i = 0; i < (iWidth / 2); i++)
- {
- for (int j = 0; j < (iHeight / 2); j++)
- {
- Color col = ImageArray[i + 79, j + 59];
- ZoomArray[i, j] = col;
- }
- }
- //Loops through half of the array, as it is 2x zoom
- for (int i = 0; i < (iWidth / 2); i++)
- {
- for (int j = 0; j < (iHeight / 2); j++)
- {
- Color col = ZoomArray[i, j];
- //i and j are multiplied by 2 to cover all of ImageArray
- ImageArray[2 * i, 2 * j] = col;
- ImageArray[2 * i + 1, 2 * j] = col;
- ImageArray[2 * i, 2 * j + 1] = col;
- ImageArray[2 * i + 1, 2 * j + 1] = col;
- }
- }
- SetBitmapFromAray();
- picImage.Image = bitmapImage;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement