您的位置:首页 > 编程语言 > Java开发

数字图像处理——用Java对图像做镜像变换

2017-05-31 22:27 239 查看
水平镜像变换,也就是把图像的像素点按照垂直中线做调换。

代码实现也很简单:

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class ImageMirror {
public static void main(String[] args) throws IOException{
File file = null;
BufferedImage image = null;

try {
file = new File("E:\\in.jpg");
image = ImageIO.read(file);

int width = image.getWidth();
int height = image.getHeight();

for (int j = 0; j < height; j++) {
int l = 0, r = width - 1;
while (l < r) {
int pl = image.getRGB(l, j);
int pr = image.getRGB(r, j);

image.setRGB(l, j, pr);
image.setRGB(r, j, pl);

l++;
r--;
}
}

file = new File("E:\\out.jpg");
ImageIO.write(image, "jpg", file);

} catch (IOException e) {
e.printStackTrace();
}
}
}


输入:



输出:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java 图像处理