/Users/lyon/j4p/src/j2d/io/TestImageIO.java
|
1 package j2d.io;
2
3 import j2d.ImageUtils;
4
5 import javax.imageio.ImageIO;
6 import javax.imageio.ImageReader;
7 import java.awt.*;
8 import java.awt.image.BufferedImage;
9 import java.io.File;
10 import java.io.IOException;
11 import java.util.Iterator;
12
13 public class TestImageIO{
14 public static void main(String args[]) {
15 System.out.println("Writer formats:");
16 printImageWriterFormats();
17 System.out.println("Reader formats:");
18 printImageReaderFormats();
19 }
20
21 public static void printImageWriterFormats() {
22 print(ImageIO.getWriterFormatNames());
23 }
24 public static Image getPNGImage(File f){
25 Iterator it = ImageIO.getImageReadersBySuffix("png");
26 while (it.hasNext()){
27 ImageReader ir = (ImageReader)it.next();
28 try {
29 BufferedImage bi = ir.read(0);
30 return ImageUtils.getImage(bi);
31 } catch (IOException e) {
32 }
33 }
34 return null;
35 }
36
37 public static void printImageReaderFormats() {
38 print(ImageIO.getReaderFormatNames());
39 }
40
41 public static void print(Object o[]) {
42 for (int i=0; i < o.length;i++)
43 System.out.println(o[i]);
44 }
45 }
46