Source Code Cross Referenced for ImageController.java in  » Web-Mail » claros-intouch2-2.2-beta » org » claros » intouch » webdisk » controllers » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Mail » claros intouch2 2.2 beta » org.claros.intouch.webdisk.controllers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.claros.intouch.webdisk.controllers;
002:
003:        import java.awt.Container;
004:        import java.awt.Graphics2D;
005:        import java.awt.Image;
006:        import java.awt.MediaTracker;
007:        import java.awt.Toolkit;
008:        import java.awt.image.BufferedImage;
009:        import java.io.BufferedInputStream;
010:        import java.io.ByteArrayOutputStream;
011:        import java.io.FileInputStream;
012:        import java.io.FileNotFoundException;
013:        import java.io.IOException;
014:        import java.util.StringTokenizer;
015:
016:        import org.claros.intouch.webdisk.models.Thumbnail;
017:
018:        public class ImageController {
019:
020:            /**
021:             * Herhangi bir url'deki resmi okur ve image objesi olarak döner.
022:             * 
023:             * @return
024:             * @throws Exception
025:             */
026:            private static BufferedImage getImage(String path) throws Exception {
027:                Toolkit toolkit = Toolkit.getDefaultToolkit();
028:                Image image = toolkit.createImage(path);
029:                MediaTracker mediaTracker = new MediaTracker(new Container());
030:                mediaTracker.addImage(image, 0);
031:                mediaTracker.waitForID(0);
032:
033:                BufferedImage img = new BufferedImage(image.getWidth(null),
034:                        image.getHeight(null), BufferedImage.TYPE_INT_RGB);
035:                Graphics2D graphics2D = img.createGraphics();
036:                graphics2D.drawImage(image, 0, 0, image.getWidth(null), image
037:                        .getHeight(null), null);
038:                try {
039:                    graphics2D.dispose();
040:                } catch (Exception e) {
041:                    // Do nothing sier
042:                }
043:                return img;
044:            }
045:
046:            /**
047:             * 
048:             * @param newWidth
049:             * @param newHeight
050:             * @param myObjWidth
051:             * @param myObjHeight
052:             * @param destObjWidth
053:             * @param destObjHeight
054:             */
055:            private static String calculateRatio(int myObjWidth,
056:                    int myObjHeight, int destObjWidth, int destObjHeight) {
057:                double widthRatio = (double) myObjWidth / (double) destObjWidth; // 2.2846
058:                double heightRatio = (double) myObjHeight
059:                        / (double) destObjHeight; // 2.02
060:
061:                double ratio = widthRatio;
062:                if (heightRatio > widthRatio) {
063:                    ratio = heightRatio;
064:                }
065:                int newWidth = (int) (myObjWidth / ratio); // 151
066:                int newHeight = (int) (myObjHeight / ratio); // 67
067:                return newWidth + "_" + newHeight;
068:            }
069:
070:            /**
071:             * 
072:             * @return
073:             */
074:            private static byte[] getCustomThumbImgBytes(String fileName,
075:                    int width, int height) {
076:                byte[] bytesOut = null;
077:                try {
078:                    Thumbnail th = new Thumbnail();
079:                    bytesOut = th.getThumb(fileName, width, height);
080:                } catch (IOException e) {
081:                    e.printStackTrace();
082:                } catch (Exception e) {
083:                    e.printStackTrace();
084:                }
085:                return bytesOut;
086:            }
087:
088:            /**
089:             * 
090:             * @return
091:             */
092:            public static byte[] getImgBytes(String path) {
093:                ByteArrayOutputStream baos = new ByteArrayOutputStream();
094:                try {
095:                    BufferedInputStream is = new BufferedInputStream(
096:                            new FileInputStream(path));
097:                    int byte_;
098:                    while ((byte_ = is.read()) != -1) {
099:                        baos.write(byte_);
100:                    }
101:                    is.close();
102:                    baos.close();
103:                } catch (FileNotFoundException e) {
104:                    e.printStackTrace();
105:                } catch (IOException e) {
106:                    e.printStackTrace();
107:                }
108:                return baos.toByteArray();
109:            }
110:
111:            /**
112:             * 
113:             * @param width
114:             * @param height
115:             * @return
116:             */
117:            public static byte[] getCustomImgBytes(String path, int width,
118:                    int height) {
119:                byte[] bytesOut = null;
120:                try {
121:                    BufferedImage img = getImage(path);
122:                    int w = img.getWidth();
123:                    int h = img.getHeight();
124:                    StringTokenizer token = new StringTokenizer(ImageController
125:                            .calculateRatio(w, h, width, height), "_");
126:                    bytesOut = ImageController.getCustomThumbImgBytes(path,
127:                            Integer.parseInt(token.nextToken()), Integer
128:                                    .parseInt(token.nextToken()));
129:                } catch (Exception e) {
130:                    e.printStackTrace();
131:                }
132:                return bytesOut;
133:            }
134:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.