001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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    }