001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.image;
016    
017    import java.awt.image.BufferedImage;
018    import java.awt.image.RenderedImage;
019    
020    import java.io.File;
021    import java.io.IOException;
022    import java.io.OutputStream;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     */
027    public class ImageProcessorUtil {
028    
029            public static BufferedImage convertImageType(
030                    BufferedImage sourceImage, int type) {
031    
032                    return getImageProcessor().convertImageType(sourceImage, type);
033            }
034    
035            public static void encodeGIF(RenderedImage renderedImage, OutputStream os)
036                    throws IOException {
037    
038                    getImageProcessor().encodeGIF(renderedImage, os);
039            }
040    
041            public static void encodeWBMP(RenderedImage renderedImage, OutputStream os)
042                    throws InterruptedException, IOException {
043    
044                    getImageProcessor().encodeWBMP(renderedImage, os);
045            }
046    
047            public static BufferedImage getBufferedImage(RenderedImage renderedImage) {
048                    return getImageProcessor().getBufferedImage(renderedImage);
049            }
050    
051            public static byte[] getBytes(
052                            RenderedImage renderedImage, String contentType)
053                    throws IOException {
054    
055                    return getImageProcessor().getBytes(renderedImage, contentType);
056            }
057    
058            public static ImageProcessor getImageProcessor() {
059                    return _imageProcessor;
060            }
061    
062            public static ImageBag read(File file) throws IOException {
063                    return getImageProcessor().read(file);
064            }
065    
066            public static ImageBag read(byte[] bytes) throws IOException {
067                    return getImageProcessor().read(bytes);
068            }
069    
070            public static RenderedImage scale(
071                    RenderedImage renderedImage, int maxHeight, int maxWidth) {
072    
073                    return getImageProcessor().scale(renderedImage, maxHeight, maxWidth);
074            }
075    
076            public void setImageProcessor(ImageProcessor imageProcessor) {
077                    _imageProcessor = imageProcessor;
078            }
079    
080            private static ImageProcessor _imageProcessor;
081    
082    }