forked from yinchuandong/JavaVerify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScaleImage.java
More file actions
66 lines (52 loc) · 1.37 KB
/
ScaleImage.java
File metadata and controls
66 lines (52 loc) · 1.37 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
package train;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import javax.imageio.ImageIO;
import javax.naming.ldap.SortControl;
import com.jhlabs.image.ScaleFilter;
/**
* 将原图片缩放成统一大小的图片
* @author wangjiewen
*
*/
public class ScaleImage {
public static void run(){
try {
File dir = new File("3_drop");
SegWaterDrop model = new SegWaterDrop();
//只列出jpg
File[] files = dir.listFiles(new FilenameFilter() {
public boolean isJpg(String file){
if (file.toLowerCase().endsWith(".jpg")){
return true;
}else{
return false;
}
}
@Override
public boolean accept(File dir, String name) {
// TODO Auto-generated method stub
return isJpg(name);
}
});
File targetDir = new File("4_scale");
if (!targetDir.exists()) {
targetDir.mkdir();
}
for (File file : files) {
BufferedImage sourceImage = ImageIO.read(file);
BufferedImage targetImage = ImageUtil.scaleImage(sourceImage);
ImageIO.write(targetImage, "JPG", new File("4_scale/" + file.getName()));
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args){
run();
}
}