Javascript

이미지 Resizing

damian 2012. 11. 26. 15:16

  try {
   String FileName = getCookieFileName(request);
   String ext = FileName.substring(FileName.lastIndexOf(".") + 1, FileName.length()).toLowerCase();
   
   if (ext.equals("bmp") || ext.equals("jpg") || ext.equals("jpeg") || ext.equals("gif") || ext.equals("png"))
   {
    // 이미지 Resizing
    resizeImage(filePath, ext);
   }
   
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

 

 


    // 이미지 Resizing
    private static void resizeImage(String filePath, String ext) throws IOException{
     // 원본 이미지 read
     BufferedImage originalImage = ImageIO.read(new File(filePath));
  int type = originalImage.getType() == 0? BufferedImage.TYPE_INT_ARGB : originalImage.getType();
     float re_width = 640, re_height = 480, org_width = 0, org_height = 0;
    
     org_width = originalImage.getWidth();
     org_height = originalImage.getHeight();
     
     if (org_width <= re_width) {
      return;
     }
     
     // 이미지 Resize
     re_height = org_height / (org_width / re_width);
     
     System.out.println("org_width : " + org_width + " , org_height : " + org_height + " , re_width : " + re_width + " , re_height : " + re_height);
     
     BufferedImage resizedImage = new BufferedImage((int)re_width, (int)re_height, type);
     Graphics2D g = resizedImage.createGraphics();
     g.drawImage(originalImage, 0, 0, (int)re_width, (int)re_height, null);
     g.dispose();
 
     // Resize 된 이미지 저장
     File fileOutputStream = new File(filePath);
     ImageIO.write(resizedImage, ext, fileOutputStream);
    }
 

'Javascript' 카테고리의 다른 글

egov list 를 json 객체로 전달 및 사용  (0) 2014.09.23
blob 이미지 파일 저장  (0) 2012.11.26
테이블 객체  (0) 2012.01.25
SetComma  (0) 2012.01.19
Select tag 에 Item 추가  (0) 2012.01.18