KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > encoders > SunPNGEncoderAdapter


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jfreechart/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22  * USA.
23  *
24  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25  * in the United States and other countries.]
26  *
27  * -------------------------
28  * SunPNGEncoderAdapter.java
29  * -------------------------
30  * (C) Copyright 2004, by Richard Atkinson and Contributors.
31  *
32  * Original Author: Richard Atkinson;
33  * Contributor(s): -;
34  *
35  * $Id: SunPNGEncoderAdapter.java,v 1.3.2.2 2005/11/24 11:28:06 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 01-Aug-2004 : Initial version (RA);
40  *
41  */

42 package org.jfree.chart.encoders;
43
44 import javax.imageio.ImageIO JavaDoc;
45 import java.awt.image.BufferedImage JavaDoc;
46 import java.io.OutputStream JavaDoc;
47 import java.io.ByteArrayOutputStream JavaDoc;
48 import java.io.IOException JavaDoc;
49
50 /**
51  * Adapter class for the Sun PNG Encoder. The ImageEncoderFactory will only
52  * return a reference to this class by default if the library has been compiled
53  * under a JDK 1.4+ and is being run using a JDK 1.4+.
54  *
55  * @author Richard Atkinson
56  */

57 public class SunPNGEncoderAdapter implements ImageEncoder {
58
59     /**
60      * Get the quality of the image encoding (always 0.0).
61      *
62      * @return A float representing the quality.
63      */

64     public float getQuality() {
65         return 0.0f;
66     }
67
68     /**
69      * Set the quality of the image encoding (not supported in this
70      * ImageEncoder).
71      *
72      * @param quality A float representing the quality.
73      */

74     public void setQuality(float quality) {
75         // No op
76
}
77
78     /**
79      * Get whether the encoder should encode alpha transparency (always false).
80      *
81      * @return Whether the encoder is encoding alpha transparency.
82      */

83     public boolean isEncodingAlpha() {
84         return false;
85     }
86
87     /**
88      * Set whether the encoder should encode alpha transparency (not
89      * supported in this ImageEncoder).
90      *
91      * @param encodingAlpha Whether the encoder should encode alpha
92      * transparency.
93      */

94     public void setEncodingAlpha(boolean encodingAlpha) {
95         // No op
96
}
97
98     /**
99      * Encodes an image in PNG format.
100      *
101      * @param bufferedImage The image to be encoded.
102      *
103      * @return The byte[] that is the encoded image.
104      *
105      * @throws IOException
106      */

107     public byte[] encode(BufferedImage JavaDoc bufferedImage) throws IOException JavaDoc {
108         ByteArrayOutputStream JavaDoc outputStream = new ByteArrayOutputStream JavaDoc();
109         encode(bufferedImage, outputStream);
110         return outputStream.toByteArray();
111     }
112
113     /**
114      * Encodes an image in PNG format and writes it to an OutputStream.
115      *
116      * @param bufferedImage The image to be encoded.
117      * @param outputStream The OutputStream to write the encoded image to.
118      * @throws IOException
119      */

120     public void encode(BufferedImage JavaDoc bufferedImage, OutputStream JavaDoc outputStream)
121         throws IOException JavaDoc {
122         if (bufferedImage == null) {
123             throw new IllegalArgumentException JavaDoc("Null 'image' argument.");
124         }
125         if (outputStream == null) {
126             throw new IllegalArgumentException JavaDoc("Null 'outputStream' argument.");
127         }
128         ImageIO.write(bufferedImage, ImageFormat.PNG, outputStream);
129     }
130
131 }
132
Popular Tags