This repository has been archived on 2022-08-05. You can view files and clone it, but cannot push or open issues or pull requests.
school-projects/ImgJava/src/main/java/io/gitlab/jfronny/ImgJava/imageProcessing/ImageUtil.java

36 lines
886 B
Java

package io.gitlab.jfronny.ImgJava.imageProcessing;
import io.gitlab.jfronny.ImgJava.util.Picture;
import java.awt.*;
/**
* Algorithmen zur Änderung der Pixelpositionen eines Pictures
* z.B. drehen, spiegeln usw.
*
* @author Thomas Schaller
* @version 1.1 (28.11.2019)
*/
public class ImageUtil {
/**
* Horizontally mirrors an image (mutates original instance)
*
* @param picture Picture to mirror
* @return The mirrored image
*/
public static Picture mirror(Picture picture) {
int w = picture.getWidth();
int h = picture.getHeight();
Color[][] pixel = picture.getPixelArray();
Color[][] pixelNeu = new Color[w][h];
for (int x = 0; x < w; x++) {
System.arraycopy(pixel[(w - 1) - x], 0, pixelNeu[x], 0, h);
}
picture.setPixelArray(pixelNeu);
return picture;
}
}