Pixel[] selectedPixels; void Crop_AbsoluteDimensions (int posX, int posY, int offsetX, int offsetY) { // current crop tool } void Crop_ToSelection () { Pixel pixelLeft = selectedPixels[0]; for (int i = 0; i < selectedPixels.Length; i++) { if (selectedPixels[i].pos.x < pixelLeft.pos.x) { pixelLeft = selectedPixels[i]; } } Pixel pixelRight = selectedPixels[0]; for (int i = 0; i < selectedPixels.Length; i++) { if (selectedPixels[i].pos.x > pixelRight.pos.x) { pixelRight = selectedPixels[i]; } } Pixel pixelUp = selectedPixels[0]; for (int i = 0; i < selectedPixels.Length; i++) { if (selectedPixels[i].pos.y > pixelUp.pos.x) { pixelUp = selectedPixels[i]; } } Pixel pixelDown = selectedPixels[0]; for (int i = 0; i < selectedPixels.Length; i++) { if (selectedPixels[i].pos.y < pixelDown.pos.x) { pixelDown = selectedPixels[i]; } } int posX = pixelLeft.pos.x; int posY = pixelDown.pos.y; int offsetX = pixelRight.pos.x - pixelLeft.pos.x; int offsetY = pixelUp.pos.y - pixelDown.pos.y; Crop_AbsoluteDimensions(posX,posY,offsetX,offsetY); }