1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.kernel.image;
16  
17  import java.awt.image.BufferedImage;
18  import java.awt.image.RenderedImage;
19  
20  import java.io.File;
21  import java.io.IOException;
22  import java.io.OutputStream;
23  
24  /**
25   * <a href="ImageProcessorUtil.java.html"><b><i>View Source</i></b></a>
26   *
27   * @author Brian Wing Shun Chan
28   */
29  public class ImageProcessorUtil {
30  
31      public static BufferedImage convertImageType(
32          BufferedImage sourceImage, int type) {
33  
34          return getImageProcessor().convertImageType(sourceImage, type);
35      }
36  
37      public static void encodeGIF(RenderedImage renderedImage, OutputStream os)
38          throws IOException {
39  
40          getImageProcessor().encodeGIF(renderedImage, os);
41      }
42  
43      public static void encodeWBMP(RenderedImage renderedImage, OutputStream os)
44          throws InterruptedException, IOException {
45  
46          getImageProcessor().encodeWBMP(renderedImage, os);
47      }
48  
49      public static BufferedImage getBufferedImage(RenderedImage renderedImage) {
50          return getImageProcessor().getBufferedImage(renderedImage);
51      }
52  
53      public static byte[] getBytes(
54              RenderedImage renderedImage, String contentType)
55          throws IOException {
56  
57          return getImageProcessor().getBytes(renderedImage, contentType);
58      }
59  
60      public static ImageProcessor getImageProcessor() {
61          return _imageProcessor;
62      }
63  
64      public static ImageBag read(File file) throws IOException {
65          return getImageProcessor().read(file);
66      }
67  
68      public static ImageBag read(byte[] bytes) throws IOException {
69          return getImageProcessor().read(bytes);
70      }
71  
72      public static RenderedImage scale(
73          RenderedImage renderedImage, int maxHeight, int maxWidth) {
74  
75          return getImageProcessor().scale(renderedImage, maxHeight, maxWidth);
76      }
77  
78      public void setImageProcessor(ImageProcessor imageProcessor) {
79          _imageProcessor = imageProcessor;
80      }
81  
82      private static ImageProcessor _imageProcessor;
83  
84  }