Lab2

Lab2 – ImageConverterTest (Due by 4/2)
Lab2 프로젝트 디렉토리 안에 모든 파일(src/*.java & bin/*.class)와 보고서(3-4장정도 – 장수제한없음)를 넣고 Lab2_학번_이름.zip
압축한 후 e-learning(http://lms.dankook.ac.kr/index.jsp)으로 제출

0 – image convert
1 – command line arguments (inputFile, outputFile, format)
2 – for/foreach
3 – if/else, switch, constant
4 – while/do-while, Scanner 클래스를 이용하여 사용자 입력받아서 image convert한다.
5 – 본인이 원하는 코드를 추가작성한다. – 예를 들어, image resize
1,2,3,4,5에 해당하는 부분을 /* 주석문 */으로 표시해준다.


// converts an image to another format
public static boolean convert(String inputImageFile, String outputImageFile, String format) {
    boolean result = false;;
    BufferedImage image = null;
    try {
        // reads input image from file
        image = ImageIO.read(new File(inputImageFile));
        // writes to the output image in specified format
        result = ImageIO.write(image, format, new File(outputImageFile));
        // prints the result
        if (result) {
            System.out.println(inputImageFile + " Image converted to " + outputImageFile + " successfully.");
        } else {
            System.out.println("Could not convert image.");
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return result;
}

public static void print(String imageFilename) {
    // reads the image
    BufferedImage image = null;
    try {
        image = ImageIO.read(new File(imageFilename));
        int width = image.getWidth();
        int height = image.getHeight();
        String ext = imageFilename.substring(imageFilename.lastIndexOf('.')+1);
        // prints the image information
        System.out.println("filename=" + imageFilename);
        System.out.println("width=" + width);
        System.out.println("height=" + height);
        System.out.println("format=" + ext);
    } catch (IOException e) {
        e.printStackTrace();
    }
}