-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageResizer.java
More file actions
57 lines (48 loc) · 1.51 KB
/
Copy pathImageResizer.java
File metadata and controls
57 lines (48 loc) · 1.51 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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package edu.ijse.semesterII.simulator.util;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
/**
*
* @author Randula
*/
public class ImageResizer {
private final int WIDTH = 390;
private final int HEIGHT = 270;
public String resize(String location)
throws IOException {
/**
* reads the new input image
*/
File inputFile = new File(location);
BufferedImage inputImage = ImageIO.read(inputFile);
/**
* create the output image
*/
BufferedImage outputImage = new BufferedImage(WIDTH, HEIGHT, inputImage.getType());
/**
* set the size of the new image
*/
Graphics2D g2d = outputImage.createGraphics();
g2d.drawImage(inputImage, 0, 0, WIDTH, HEIGHT, null);
g2d.dispose();
/**
* set the new file name
*/
String[] formatName = location.split("\\.");
System.out.println(location);
String outputPath = formatName[0] + "1." + formatName[1];
/**
* writes the new image into the file
*/
ImageIO.write(outputImage, "png", new File(outputPath));
return outputPath;
}
}