문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 | ||
algorithms:이미지썸네일crop크기계산 [2010/12/08 17:36] kwon37xi |
algorithms:이미지썸네일crop크기계산 [2010/12/09 11:22] kwon37xi |
||
---|---|---|---|
줄 1: | 줄 1: | ||
- | ====== Image Thumbnail 생성시 Thumbnail | + | ====== Image Thumbnail 생성시 Thumbnail |
이미지 파일의 썸네일을 만들 때 강제로 썸네일의 지정 크기에 맞게 크기를 고정하거나, | 이미지 파일의 썸네일을 만들 때 강제로 썸네일의 지정 크기에 맞게 크기를 고정하거나, | ||
- | C#으로 만들어진 썸네일의 | + | C#으로 만들어진 썸네일의 |
- | 이의 | + | 이의 |
+ | <code java> | ||
+ | public Dimension calculateCropSize(Dimension originalSize, | ||
+ | Dimension thumbnailSize) { | ||
+ | double originalAspectRatio = originalSize.getWidth() | ||
+ | / originalSize.getHeight(); | ||
+ | double thumbnailAspectRatio = thumbnailSize.getWidth() | ||
+ | / thumbnailSize.getHeight(); | ||
+ | |||
+ | if (originalAspectRatio == thumbnailAspectRatio) { | ||
+ | return new Dimension(originalSize); | ||
+ | } | ||
+ | |||
+ | int targetWidth = originalSize.width; | ||
+ | int targetHeight = originalSize.height; | ||
+ | |||
+ | if (thumbnailAspectRatio > originalAspectRatio) { | ||
+ | targetHeight = (int) (originalSize.getWidth() * (thumbnailSize | ||
+ | .getHeight() / thumbnailSize.getWidth())); | ||
+ | } else { | ||
+ | targetWidth = (int) (originalSize.getHeight() * thumbnailAspectRatio); | ||
+ | } | ||
+ | |||
+ | return new Dimension(targetWidth, | ||
+ | } | ||
+ | </ |