1.//pizza
2.package com;
3.
4.import java.io.FileOutputStream;
5.
6.
7.
8.public class ToImg {
9. public static void main(String[] args) throws Exception {
10. toSmaillImg("untitled.bmp","thumb.bmp");
11. }
12.
13. public static void toSmaillImg(String filePath,String thumbPath) throws Exception{
14. String newurl =thumbPath;
15. java.awt.Image bigJpg = javax.imageio.ImageIO.read(new java.io.File(filePath));
16. float tagsize = 100;
17. int old_w = bigJpg.getWidth(null);
18. int old_h = bigJpg.getHeight(null);
19. int new_w = 0;
20. int new_h = 0;
21. float tempdouble;
22. tempdouble = old_w > old_h ? old_w/tagsize : old_h/tagsize;
23. new_w = Math.round(old_w/tempdouble);
24. new_h = Math.round(old_h/tempdouble);
25. java.awt.image.BufferedImage tag = new java.awt.image.BufferedImage(new_w,new_h,java.awt.image.BufferedImage.TYPE_INT_RGB);
26. tag.getGraphics().drawImage(bigJpg,0,0,new_w,new_h,null);
27. FileOutputStream newimage = new FileOutputStream(newurl);
28. com.sun.image.codec.jpeg.JPEGImageEncoder encoder = com.sun.image.codec.jpeg.JPEGCodec.createJPEGEncoder(newimage);
29. encoder.encode(tag);
30. newimage.close();
31. }
32.}