-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMirrorImage.java
More file actions
66 lines (55 loc) · 1.72 KB
/
MirrorImage.java
File metadata and controls
66 lines (55 loc) · 1.72 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
63
64
65
66
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("/home/dell/Desktop//input.png");
simg = ImageIO.read(f);
}
catch(IOException e)
{
System.out.println("Error: " + e);
}
// Read source image file
// Get source image dimension
int width = simg.getWidth();
int height = simg.getHeight();
System.out.println(width);
System.out.println(height);
// BufferedImage for mirror image
BufferedImage mimg = new BufferedImage(width, height,
BufferedImage.TYPE_INT_ARGB);
// Create mirror image pixel by pixel
for (int y = 0; y < height; y++)
{
for (int lx = 0, rx = width - 1; lx < width; lx++, rx--)
{
int p = simg.getRGB(lx, y);
mimg.setRGB(rx, y, p);
}
}
int width1 = mimg.getWidth();
int height1 = mimg.getHeight();
System.out.println(width1);
System.out.println(height1);
try
{
f = new File("/home/dell/Desktop//output.png");
ImageIO.write(mimg, "png", f);
}
catch(IOException e)
{
System.out.println("Error: " + e);
}
}
}