posted 5 years ago
An image is essentially a grid of pixels. A pixel is a singular point of color, with a red/green/blue component. However this detail doesn't matter for the logic of cutting an image in half.
Imagine, for simplicity's sake, that we have the following grid of integers:
[1, 2, 3, 4
4, 5, 6, 7
7, 8, 9, 9,
3, 4, 5, 6]
Which forms a 4 x 4 image.
What pixels would you need to keep in order to cut the grid horizontally? Well you'd need to keep either the top half or the bottom half:
[1, 2, 3, 4
4, 5, 6, 7]
or:
[7, 8, 9, 9,
3, 4, 5, 6]
What pixels would you need to do vertically? The first or second half, going from right to left.
[1, 2
4, 5
7, 8
3, 4]
or:
[3, 4
6, 7
9, 9,
5, 6]
Can you write a loop that would do this for a 2D Array of integers?
(hint: it's going to be a nested loop with one of your indices being x, and the other being y.)
If you can do that, then you're 90% of the way there to doing it with an Image.