logo

English

이곳의 프로그래밍관련 정보와 소스는 마음대로 활용하셔도 좋습니다. 다만 쓰시기 전에 통보 정도는 해주시는 것이 예의 일것 같습니다. 질문이나 오류 수정은 siseong@gmail.com 으로 주세요. 감사합니다.

Android - 이미지(비트맵) 리사이징

by digipine posted Nov 01, 2017
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

안드로이드에서 비트맵 리사이징이 필요한 이유는 몇가지가 있을 수 있는데,

- 이미지 사이즈가 너무 커서 줄여야 하는 경우
- 인텐트를 이용하여 주고 받을 때 데이터 사이즈가 커서 안되는 경우
- 기타 메모리 부족 문제

어쨌거나 안드로이드에서 비트맵 리사이징 하는 방법에는 아래 코드와 같이 하는 방법이 있다.


BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4;
Bitmap src = BitmapFactory.decodeFile("/sdcard/image.jpg", options);
Bitmap resized = Bitmap.createScaledBitmap(src, dstWidth, dstHeight, true);

inSampleSize 값을 적절히 사용해도 되겠지만 특정 너비나 높이값에 맞추어야 할 경우도 있다.

아래 코드는 높이 118에 맞춰서(정확하게는 118 이하로) 리사이징 하는 방법이다.

 

Uri imgUri = data.getData();

Bitmap bitmap = Images.Media.getBitmap(getContentResolver(), imgUri);

int height = bitmap.getHeight();

int width = bitmap.getWidth();

// Toast.makeText(this, width + " , " + height, Toast.LENGTH_SHORT).show();

Bitmap resized = null;

while (height > 118) {

resized = Bitmap.createScaledBitmap(bitmap, (width * 118) / height, 118, true);

        height = resized.getHeight();

        width = resized.getWidth();

}

// Toast.makeText(this, width + " , " + height, Toast.LENGTH_SHORT).show();

coverImageView.setImageBitmap(resized);

 
TAG •

List of Articles
No. Subject Author Date Views
22 안드로이드 개발시 API Key, 암호화 정보 코드에서 숨기는 방법, Kotlin DSL의 경우 lizard2019 2023.06.20 193
21 구글에서 제공하는 안드로이드 개발 기초 학습코스 file digipine 2022.03.18 378
20 Toolchain Error 'No such file or directory' 해결방법 lizard2019 2019.12.19 1371
19 Ubuntu 16.0.4 openjdk 7 설치방법 lizard2019 2019.12.19 826
18 Ubuntu 리눅스 fastboot 설치 lizard2019 2019.12.13 1502
17 atomic vs volatile vs synchronized file 엉뚱도마뱀 2017.12.18 1186
16 Atomic Operation에 대해서 엉뚱도마뱀 2017.12.18 1226
15 Android 하드웨어 코덱 포팅하기, OpenCore, OpenMAX digipine 2017.11.03 1609
14 Ubuntu 기본 쉘 dash 대신 bash로 설정 digipine 2017.11.02 703
13 [안드로이드] 가속도 (Accelerometer)센서 Shake 이벤트 예제 digipine 2017.11.02 1627
12 Android - 블루투스 BLE 개발하기 digipine 2017.11.02 16583
11 안드로이드 Native C 코드에서 Intent 보내는 방법 digipine 2017.11.02 1296
10 안드로이드 시스템 개발시 mmm 커멘드 사용법 digipine 2017.11.01 1168
» Android - 이미지(비트맵) 리사이징 digipine 2017.11.01 1306
8 [Java] SortedSet과 Comparable을 이용한 정렬(Sort) digipine 2017.10.29 772
7 Android - AlarmManager를 이용해서 서비스 실행 시키는 코드 digipine 2017.10.29 498
6 Android - 슬립모드 (Sleep Mode) 방지 코드 digipine 2017.10.29 2395
5 Android - Browser 에서 Activity 실행하기 file digipine 2017.10.29 712
4 안드로이드 파일 입출력시 한글 깨짐 문제 digipine 2017.10.29 1643
3 Android 기반 Application Ant 빌드 방법 digipine 2017.10.29 537
Board Pagination Prev 1 2 Next
/ 2