2 * Copyright (c) 2018. Developed by Hedgecode.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.hedgecode.chess.img;
19 import javax.imageio.ImageIO;
22 * Supported image formats for reading/writing.
24 * @author Dmitry Samoshin aka gotty
26 public enum ImageFormat {
28 PNG ( new String[]{"png"} ),
29 GIF ( new String[]{"gif"} ),
30 JPG ( new String[]{"jpg", "jpeg"} ),
31 SVG ( new String[]{"svg"} ), // todo
32 BMP ( new String[]{"bmp", "wbmp"} );
34 private String[] fortmatExts;
36 private boolean isRead;
37 private boolean isWrite;
39 ImageFormat(String[] exts) {
42 ImageIO.getReaderFormatNames(), fortmatExts
45 ImageIO.getWriterFormatNames(), fortmatExts
49 public String getExt() {
50 return fortmatExts[0];
53 public String[] getExts() {
57 public boolean isRead() {
61 public boolean isWrite() {
65 public static ImageFormat findFormat(String formatName) {
66 if (formatName != null) {
67 for (ImageFormat imageFormat : ImageFormat.values()) {
68 if (isExist(imageFormat.getExts(), formatName))
75 private static boolean isExist(String[] names, String... args) {
76 for (String arg : args) {
77 for (String name : names) {
78 if (arg.equalsIgnoreCase(name))
87 public static void main(String[] args) {
88 ImageFormat imageFormat = JPG;
89 System.out.println("Supported format: " + imageFormat);
90 imageFormat = findFormat("jpeg");
91 imageFormat = findFormat("svg");
92 imageFormat = findFormat("jpeeg");