Image Processing – Image Flipping / Mirroring
This technique is basically same as rotation, however, it transforms rotation with a reverse direction.
– For vertical flipping: [ x = x, y = y * -1 ]
– For horizontal flipping: [ x = x * -1, y = y ]
By using matrix transformation, we’ll get nice results:
Here the implementation:
// type definition public static final int FLIP_VERTICAL = 1; public static final int FLIP_HORIZONTAL = 2; public static Bitmap flip(Bitmap src, int type) { // create new matrix for transformation Matrix matrix = new Matrix(); // if vertical if(type == FLIP_VERTICAL) { // y = y * -1 matrix.preScale(1.0f, -1.0f); } // if horizonal else if(type == FLIP_HORIZONTAL) { // x = x * -1 matrix.preScale(-1.0f, 1.0f); // unknown type } else { return null; } // return transformed image return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true); }
Hope you like it!
Cheers,
Pete Houston
Please tell me if the same can be done for videos. If so kindly help me
Thanks
hey, what is your email? I want to send you my app so you can see how it looks like after your tutorials! Thanks
Hay Junior. Can you share you app with me? I am really interested to see how these code snippets actually work.