KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > media > format > image > iio > IIOMediaFormatFactory


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package org.jboss.media.format.image.iio;
9
10 import java.util.HashMap JavaDoc;
11 import java.util.Iterator JavaDoc;
12 import java.util.Map JavaDoc;
13
14 import javax.imageio.ImageIO JavaDoc;
15 import javax.imageio.ImageReader JavaDoc;
16
17 /**
18  * Creates <code>MediaFormat</code>s based on the Java Image I/O API.
19  *
20  * @version <tt>$Revision: 1.2 $</tt>
21  * @author <a HREF="mailto:ricardoarguello@users.sourceforge.net">Ricardo ArgŁello</a>
22  */

23 public class IIOMediaFormatFactory
24 {
25    public static Map JavaDoc createMediaFormats()
26    {
27       Map JavaDoc mediaFormats = new HashMap JavaDoc();
28
29       // PNG:
30
Iterator JavaDoc imageReaders = ImageIO.getImageReadersByFormatName("png");
31       ImageReader JavaDoc imageReader = (ImageReader JavaDoc) imageReaders.next();
32       mediaFormats.put("png", new PNGMediaFormat(imageReader));
33
34       /*ImageReader pngImageReader = getImageReaderByFormatName("png");
35       ImageReader jpegImageReader = getImageReaderByFormatName("jpeg");
36       ImageReader gifImageReader = getImageReaderByFormatName("gif");
37
38       // StandardMediaFormat (just testing):
39       mediaFormats.put("png", new StandardMediaFormat(pngImageReader));
40       mediaFormats.put("jpeg", new StandardMediaFormat(jpegImageReader));
41       mediaFormats.put("gif", new StandardMediaFormat(gifImageReader));*/

42
43       return mediaFormats;
44    }
45
46    private static ImageReader JavaDoc getImageReaderByFormatName(String JavaDoc formatName)
47    {
48       Iterator JavaDoc imageReaders = ImageIO.getImageReadersByFormatName(formatName);
49       return (ImageReader JavaDoc) imageReaders.next();
50    }
51 }
52
Popular Tags