티스토리 뷰
public Bitmap scaleCenterCrop(Bitmap source, int newHeight, int newWidth) {
int sourceWidth = source.getWidth();
int sourceHeight = source.getHeight();
// Compute the scaling factors to fit the new height and width, respectively.
// To cover the final image, the final scaling will be the bigger
// of these two.
float xScale = (float) newWidth / sourceWidth;
float yScale = (float) newHeight / sourceHeight;
float scale = Math.max(xScale, yScale);
// Now get the size of the source bitmap when scaled
float scaledWidth = scale * sourceWidth;
float scaledHeight = scale * sourceHeight;
// Let's find out the upper left coordinates if the scaled bitmap
// should be centered in the new size give by the parameters
float left = (newWidth - scaledWidth) / 2;
float top = (newHeight - scaledHeight) / 2;
// The target rectangle for the new, scaled version of the source bitmap will now
// be
RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);
// Finally, we create a new bitmap of the specified size and draw our new,
// scaled bitmap onto it.
Bitmap dest = Bitmap.createBitmap(newWidth, newHeight, source.getConfig());
Canvas canvas = new Canvas(dest);
canvas.drawBitmap(source, null, targetRect, null);
return dest;
}
'프로그래밍 > android' 카테고리의 다른 글
[android] Android Bitmap Utility(resize, crop) 클래스 (0) | 2015.05.12 |
---|---|
[android] 오픈소스 (0) | 2015.05.07 |
[android] Process가 실행중인지 여부 확인 (1) | 2015.03.27 |
[android]해시 키 구하는 메소드 (0) | 2015.01.07 |
[android] ViewPager 시작시 원하는 position(item)으로 가기 (0) | 2015.01.06 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 참나무숯불닭갈비
- 남자화장품
- ShardPreferenes
- xcode7
- 안드로이드
- Xcode
- 킹스맨
- serialize
- 막국수
- git flow
- xcode8
- 리엔케이
- custom font
- ListView
- 가평휴게소
- cocoapods
- 코드 하이라이트
- keyboard
- Android
- 아이콘 사이즈
- gitgub
- android jar
- 엘지
- resize
- 안드로이드 라이브러리
- 봄봄봄
- 휴게소
- ios
- crop
- Re:NK
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
글 보관함