Java Image Flip flipPixels(int[] imgPixels, int imgw, int imgh)

Here you can find the source of flipPixels(int[] imgPixels, int imgw, int imgh)

Description

Flip an array of pixels vertically

License

Open Source License

Parameter

Parameter Description
imgPixels the pixels contained within the image
imgw the width of the image
imgh the hieght of the image

Return

int[] the pixel array fliped

Declaration

public static int[] flipPixels(int[] imgPixels, int imgw, int imgh) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from   w w  w .  j  a va 2s . c  o  m*/
     * Flip an array of pixels vertically
     *
     * @param imgPixels the pixels contained within the image
     * @param imgw the width of the image
     * @param imgh the hieght of the image
     *
     * @return int[] the pixel array fliped
     */
    public static int[] flipPixels(int[] imgPixels, int imgw, int imgh) {
        int[] flippedPixels = null;
        if (imgPixels != null) {
            flippedPixels = new int[imgw * imgh];
            for (int y = 0; y < imgh; y++) {
                for (int x = 0; x < imgw; x++) {
                    flippedPixels[((imgh - y - 1) * imgw) + x] = imgPixels[(y * imgw) + x];
                }
            }
        }
        return flippedPixels;
    }
}

Related

  1. flipImage(int stride, int height, int b[])
  2. flipImage(Object nativeImage, boolean flipHorizontal, boolean flipVertical)
  3. flipImageVertically(Image img)