KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > svggen > CachedImageHandlerPNGEncoder


1 /*
2
3    Copyright 2001,2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.svggen;
19
20 import java.awt.image.BufferedImage JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.io.OutputStream JavaDoc;
23
24 import org.apache.batik.ext.awt.image.codec.ImageEncoder;
25 import org.apache.batik.ext.awt.image.codec.PNGImageEncoder;
26
27 /**
28  * GenericImageHandler which caches PNG images.
29  *
30  * @author <a HREF="mailto:paul_evenblij@compuware.com">Paul Evenblij</a>
31  * @version $Id: CachedImageHandlerPNGEncoder.java,v 1.5 2004/08/18 07:14:59 vhardy Exp $
32  */

33 public class CachedImageHandlerPNGEncoder extends DefaultCachedImageHandler {
34     public static final String JavaDoc CACHED_PNG_PREFIX = "pngImage";
35     public static final String JavaDoc CACHED_PNG_SUFFIX = ".png";
36
37     protected String JavaDoc refPrefix = "";
38
39     /**
40      * @param imageDir directory where this handler should generate images.
41      * If null, an IllegalArgumentException is thrown.
42      * @param urlRoot root for the urls that point to images created by this
43      * image handler. If null, then the url corresponding to imageDir
44      * is used.
45      */

46     public CachedImageHandlerPNGEncoder(String JavaDoc imageDir, String JavaDoc urlRoot)
47         throws SVGGraphics2DIOException {
48         refPrefix = urlRoot + "/";
49         setImageCacher(new ImageCacher.External(imageDir,
50                                                 CACHED_PNG_PREFIX,
51                                                 CACHED_PNG_SUFFIX));
52     }
53     
54     
55     /**
56      * Uses PNG encoding.
57      */

58     public void encodeImage(BufferedImage JavaDoc buf, OutputStream JavaDoc os)
59             throws IOException JavaDoc {
60         ImageEncoder encoder = new PNGImageEncoder(os, null);
61         encoder.encode(buf);
62     }
63
64     public int getBufferedImageType(){
65         return BufferedImage.TYPE_INT_ARGB;
66     }
67
68     public String JavaDoc getRefPrefix(){
69         return refPrefix;
70     }
71 }
72
Popular Tags