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
Raw Normal View History

2021-05-05 09:35:18 +02:00
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 {
/**
2021-06-08 19:42:42 +02:00
* Horizontally mirrors an image (mutates original instance)
2021-05-05 09:35:18 +02:00
*
2021-06-08 19:42:42 +02:00
* @param picture Picture to mirror
* @return The mirrored image
2021-05-05 09:35:18 +02:00
*/
2021-06-08 19:42:42 +02:00
public static Picture mirror(Picture picture) {
int w = picture.getWidth();
int h = picture.getHeight();
2021-05-05 09:35:18 +02:00
2021-06-08 19:42:42 +02:00
Color[][] pixel = picture.getPixelArray();
Color[][] pixelNeu = new Color[w][h];
2021-05-05 09:35:18 +02:00
2021-06-08 19:42:42 +02:00
for (int x = 0; x < w; x++) {
System.arraycopy(pixel[(w - 1) - x], 0, pixelNeu[x], 0, h);
2021-05-05 09:35:18 +02:00
}
2021-06-08 19:42:42 +02:00
picture.setPixelArray(pixelNeu);
return picture;
2021-05-05 09:35:18 +02:00
}
}