-
-
Notifications
You must be signed in to change notification settings - Fork 23
Flip
Nick edited this page Jan 28, 2020
·
6 revisions
There are multiple ways to flip an image. In this library I choose the easy way, but this is not the fastest.
At first you create a new blank image with the dimensions form the original. Than you have to iterate every pixel. The current pixel will get a new position for the flip. In horizontal the new x position is the image width - the current x position - 1
of the pixel. The -1 is necessary to "correct" the image width, because x is the index and begins with 0. A vertical flip is the same with the image height
. Now you have the new pixel position and the pixel could placed in the blank image.
int newx = horizonal ? (image.width - x) - 1 : x;
int newy = vertical ? (image.height - y) - 1 : y;