forked from yusufshakeel/Java-Image-Processing-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMirrorImage.java
More file actions
62 lines (52 loc) · 1.77 KB
/
MirrorImage.java
File metadata and controls
62 lines (52 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* File: MirrorImage.java
*
* Description:
* Create a mirror image.
*
* @author Yusuf Shakeel
* Date: 04-04-2014 fri
*/
import java.io.File;
import java.io.IOException;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
public class MirrorImage{
public static void main(String args[])throws IOException{
//BufferedImage for source image
BufferedImage simg = null;
//File object
File f = null;
//read source image file
try{
f = new File("D:\\Image\\audrey.jpg");
simg = ImageIO.read(f);
}catch(IOException e){
System.out.println("Error: " + e);
}
//get source image dimension
int width = simg.getWidth();
int height = simg.getHeight();
//BufferedImage for mirror image
BufferedImage mimg = new BufferedImage(width*2, height, BufferedImage.TYPE_INT_ARGB);
//create mirror image pixel by pixel
for(int y = 0; y < height; y++){
for(int lx = 0, rx = width*2 - 1; lx < width; lx++, rx--){
//lx starts from the left side of the image
//rx starts from the right side of the image
//get source pixel value
int p = simg.getRGB(lx, y);
//set mirror image pixel value - both left and right
mimg.setRGB(lx, y, p);
mimg.setRGB(rx, y, p);
}
}
//save mirror image
try{
f = new File("D:\\Image\\Output.png");
ImageIO.write(mimg, "png", f);
}catch(IOException e){
System.out.println("Error: " + e);
}
}//main() ends here
}//class ends here