내용

글번호 11
작성자 heojk
작성일 2016-04-13 00:00:00
제목 Replacing the deprecated Java JPEG classes for Java 7
내용 jdk 1.6 까지 public static void saveAsJPEG(File file_name, BufferedImage bimage){ try { //write out data to create image in temp dir FileOutputStream out=new FileOutputStream(file_name); JPEGImageEncoder as_jpeg=JPEGCodec.createJPEGEncoder(out); as_jpeg.encode(bimage); out.close(); } catch (Exception e) { e.printStackTrace(); } } jdk 1.7 부터 public static void saveAsJPEG(File file_name, BufferedImage bimage){ FileOutputStream out = null; try { //write out data to create image in temp dir out=new FileOutputStream(file_name); ImageIO.write(bimage, "JPEG", out); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } finally { if(out!=null) { try { out.close(); } catch(Exception e) {} } } }