>> Read No. 3320 article  
java 버젼

등록 2003-01-29 15:42:00     조회 6
이름 ttr    

		저가 사용하는 jpeg파일을 스케일을 변환하는 java에서 사용하는 메서드입니다.
static한 메서드이니깐 필요한 class에 추가한 후 이용하시면 됩니다.
jpeg파일만 test하였습니다.
 /**
	 사용하기 위하여는 아래와 같이 import 한다.
	import java.awt.Image;
	import java.awt.Graphics2D;
	import java.awt.geom.AffineTransform;
	import java.awt.image.BufferedImage;
	import javax.swing.ImageIcon;
	import com.sun.image.codec.jpeg.JPEGCodec;
	import com.sun.image.codec.jpeg.JPEGImageEncoder;
 	@param orig 원본 이미지 파일명 ex: /tmp/a.jpg
	@param thumb 생성될 이미지 파일명 ex : /temp/b.jpg
	@param maxDim 생성될 이미지의 가로길이. ex : 400 (원본이미지의 가로를 400으로 줄인다. 세로
는 같은 비율로 줄어든다.) */
    public static void createThumbnail( String orig, String thumb, int maxDim) {
        try {
            // Get the image from a file.
            Image inImage = new ImageIcon(
                          orig).getImage();
	    int iwidth = inImage.getWidth(null);
	    //System.out.println(iwidth);
	    if(maxDim > iwidth)
		maxDim = iwidth;
             // Determine the scale.
	    double scale = (double)maxDim/(
	       double)inImage.getHeight(null);
            if (inImage.getWidth(
             null) > inImage.getHeight(null)) {
                scale = (double)maxDim/(
                double)inImage.getWidth(null);
            }
             // Determine size of new image.
            //One of them
            // should equal maxDim.
            int scaledW = (int)(
             scale*inImage.getWidth(null));
            int scaledH = (int)(
             scale*inImage.getHeight(null));
             // Create an image buffer in
            //which to paint on.
            BufferedImage outImage =
              new BufferedImage(scaledW, scaledH,
                BufferedImage.TYPE_INT_RGB);
             // Set the scale.
            AffineTransform tx =
              new AffineTransform();
             // If the image is smaller than
            //the desired image size,
            // don't bother scaling.
            if (scale < 1.0d) {
                tx.scale(scale, scale);
            }
             // Paint image.
            Graphics2D g2d =
             outImage.createGraphics();
            g2d.drawImage(inImage, tx, null);
            g2d.dispose();
             // JPEG-encode the image
            //and write to file.
            OutputStream os =
             new FileOutputStream(thumb);
            JPEGImageEncoder encoder =
              JPEGCodec.createJPEGEncoder(os);
            encoder.encode(outImage);
            os.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }--아내와 나
사랑이야기를 쓴다.
이름
암호
  목록보기 윗글 아랫글
글쓰기
답장쓰기 수정 삭제
정규표현식 [ 상세 검색 ]
페이지로딩: [ 1.13 초 ] 작업시간: [ 0.01 초 ]

Copyleft 1999-2026 by JSBoard Open Project
Theme Designed by IDOO All right reserved
[TOP]

적수네 동네
+
| 적수네 동네
| 공부방
| 리눅스 잡지 서고
| LSN 소스
| 링크 모음
+---+
게시판
+
| 떠들어보세!
| 질문과 답변
| 새소식과 정보
| 1원짜리 팁?
| 대화방
+---+
칼럼?
+
| 세하 훔쳐보기
| Welcome2nite
| 혜진의 염장판
+---+
리눅스 상표권
+
| 반대 서명란
| 토론 게시판
+---+
GNU
+
| GNU 선언문
| GNU GPL
| GNU 미러 목록
+---+
프로젝트?
+
| 리눅스카운터
| RC5DES
| 실질헌법 제작
+---+
커널 소식
+
| 안정 버젼: 2.4.14
+---+
테마 선택
+
LSN 방송국?
+
| OFF AIR
+---+
회원
+
| 로그인
+---+
[ 적수네 동네 ] [ 리눅스 상표권 독점 반대 ] [ 한글 리눅스 문서 프로젝트 ] [ KrLine ] [ 사랑넷 ] [ Valid HTML 4.0! ] [ SlashDot ] [ Freshmeat ]
Copyleft (C) 1998-2001 Byeong-Chan Kim . License
TIME: 1791021510
System by WYZsoft, HDD by I.O.Linux, Mizi Research, Embryo, WOWLINUX, Domain by SarangNet, Network by KrLine.