반응형
셋팅해야 되는 이미지의 사이즈가 일정하지 않을 경우 변경될 Width의 비율에 맞춰 Height를 수정하면 원본 비율에 맞는 이미지로 변경할 수 있습니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
public static Bitmap setRatioImage(Context context, ImageView view, Bitmap src, int imageId) {
Bitmap bitmap;
try {
int viewWidth = view.getWidth();
int srcWidth = src.getWidth();
float ratio = (float)viewWidth / (float)srcWidth;
float height = src.getHeight() * ratio;
bitmap = Bitmap.createScaledBitmap(src, (int)viewWidth, (int)height, false);
} catch (Exception e) {
// TODO: handle exception
bitmap = BitmapFactory.decodeResource(context.getResources(), imageId);
}
return bitmap;
}
|
cs |
반응형
'Android' 카테고리의 다른 글
웹 경로 동영상의 Thumbnail 이미지 가져오기 (0) | 2018.05.11 |
---|---|
폴더/파일의 Auto Media Scanning 방지 (0) | 2018.05.08 |
아이콘 드래그 앤 드롭 - 게임 스킬 창 (28) | 2012.05.06 |
마이크 음량 디스플레이 하기 (11) | 2012.04.23 |
팝업 Activity의 애니매이션 처리 (0) | 2012.04.21 |