import javax.imageio.ImageIO;
/**
- * Supported image formats for reading/writing.
+ * Supported image formats for reading/writing, indicated by type.
*
* @author Dmitry Samoshin aka gotty
*/
public enum ImageFormat {
- PNG ( new String[]{"png"} ),
- GIF ( new String[]{"gif"} ),
- JPG ( new String[]{"jpg", "jpeg"} ),
- SVG ( new String[]{"svg"} ), // todo
- BMP ( new String[]{"bmp", "wbmp"} );
+ PNG ( Type.BITMAP, new String[]{"png"} ),
+ GIF ( Type.BITMAP, new String[]{"gif"} ),
+ JPG ( Type.BITMAP, new String[]{"jpg", "jpeg"} ),
+ BMP ( Type.BITMAP, new String[]{"bmp", "wbmp"} ),
+ SVG ( Type.VECTOR, new String[]{"svg"} );
- private String[] fortmatExts;
+ enum Type {
+
+ BITMAP,
+ VECTOR
+
+ }
+
+ private Type formatType;
+ private String[] formatExts;
private boolean isRead;
private boolean isWrite;
private static String[] allAvailableExts;
- ImageFormat(String[] exts) {
- fortmatExts = exts;
+ ImageFormat(Type type, String[] exts) {
+ formatType = type;
+ formatExts = exts;
isRead = isExist(
- ImageIO.getReaderFormatNames(), fortmatExts
+ ImageIO.getReaderFormatNames(), formatExts
);
isWrite = isExist(
- ImageIO.getWriterFormatNames(), fortmatExts
+ ImageIO.getWriterFormatNames(), formatExts
);
}
+ public Type getType() {
+ return formatType;
+ }
+
public String getExt() {
- return fortmatExts[0];
+ return formatExts[0];
}
public String[] getExts() {
- return fortmatExts;
+ return formatExts;
}
public boolean isRead() {
return false;
}
-
-/*
- public static void main(String[] args) {
- ImageFormat imageFormat = JPG;
- System.out.println("Supported format: " + imageFormat);
- imageFormat = findFormat("jpeg");
- imageFormat = findFormat("svg");
- imageFormat = findFormat("jpeeg");
- }
-*/
-
}
\ No newline at end of file