20. {
21. if ( inChannel != null )
22. {
23. inChannel.close();
24. }
25. if ( outChannel != null )
26. {
27. outChannel.close();
28. }
29. }
30. }
8. 创建图片的缩略图
1. private void createThumbnail(String filename, int thumbWidth, int thumbHeight, int
quality, String outFilename)
2. throws InterruptedException, FileNotFoundException, IOException
3. {
4. // load image from filename
5. Image image = Toolkit.getDefaultToolkit().getImage(filename);
6. MediaTracker mediaTracker = new MediaTracker(new Container());
7. mediaTracker.addImage(image, 0);
8. mediaTracker.waitForID(0);
9. // use this to test for errors at this point:
System.out.println(mediaTracker.isErrorAny());
10.
11. // determine thumbnail size from WIDTH and HEIGHT
12. double thumbRatio = (double)thumbWidth / (double)thumbHeight;
13. int imageWidth = image.getWidth(null);
14. int imageHeight = image.getHeight(null);
15. double imageRatio = (double)imageWidth / (double)imageHeight;
16. if (thumbRatio < imageRatio) {
17. thumbHeight = (int)(thumbWidth / imageRatio);
18. } else {
19. thumbWidth = (int)(thumbHeight * imageRatio);
20. }
21.
22. // draw original image to thumbnail image object and
23. // scale it to the new size on-the-fly
24. BufferedImage thumbImage = new BufferedImage(thumbWidth, thumbHeight,
BufferedImage.TYPE_INT_RGB);
25. Graphics2D graphics2D = thumbImage.createGraphics();
26. graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
27. graphics2D.drawImage(image, 0, 0, thumbWidth, thumbHeight, null); 28.
20个非常有用的Java程序片段_初二语文_语文_初中教育_教育专区。非常有用,切莫错过20 个非常有用的 Java 程序片段 1. 字符串有整型的相互转换 String a = ...
20非常有用的Java程序片段_计算机软件及应用_IT/计算机_专业资料。20段非常有用的java程序片段,对于程序员来说是一个好的收藏代码...
下面是 20 个非常有用的 Java 程序片段,希望能对你有用。 1. 字符串有整型的相互转换 1 2 3 String a = String.valueOf(2); //integer to numeric ...
20 非常有用的 Java 程序片段(1) 2013-06-14 14:57 陈皓 酷壳网 我要评论(0) 字号:T T 下面是 20 个非常有用的 Java 程序片段,希望能对你有用...
二十个JAVA程序代码 30页 2财富值 最新JAVA编程题全集(50题及... 31页 ...将Java中的util.Date转换成sql.Date这一片段显示如何将一个java util Date转换...
二十个JAVA程序代码 30页 1下载券 一些非常有用的JAVA常用... 7页 1下载...(2)向Java文件中添加文本 public void addFile() { //Updated: Thanks Simone...
20个JAVA入门者用得到的代码段20个JAVA入门者用得到的代码段隐藏>> 下面是20个非常有用的Java程序片段,希望能对你有用。 1. 字符串有整型的相互转换 Java...
二十个JAVA程序代码 30页 2财富值 20个开发人员非常有用的Ja... 280页 1...获取 Java 现在正调用的方法名 String methodName = Thread.currentThread().get...
JAVA有用的代码段_建筑/土木_工程科技_专业资料。JAVA有用的代码段下面是 20 个非常有用的 Java 程序片段,希望能对你有用。 1. 字符串有整型的相互转换 ...
Android 编程 14 个很有用的代码片段 1、查看是否有存储卡插入 [java] view plaincopyprint? 1. String status=Environment.getExternalStorageState(); 2. 3. ...
热门文档