1
Image src = javax.imageio.ImageIO.read(file);
2
int width = 116; // 小圖寬
3
int height = 90; // 小圖高
4
BufferedImage tag = new BufferedImage(width,height, BufferedImage.TYPE_INT_RGB);
5
// 繪制縮小后的圖
6
tag.getGraphics().drawImage(src, 0, 0,width, height, null);
7
String spicBasePath = baseSmallPicturePath+ getFileDir(curname);
8
String smallpicpath = tomcatPath+spicBasePath;
9
smallpicpath = new FileOperate().createDir(smallpicpath);
10
File smallpicfile = new File(smallpicpath,newfilename);
11
// 輸出到文件流
12
FileOutputStream out = new FileOutputStream(smallpicfile);
13
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
14
encoder.encode(tag); // 近JPEG編碼
15
out.close();

2

3

4

5

6

7

8

9

10

11

12

13

14

15
