블로그 이미지
Kanais
Researcher & Developer 퍼즐을 완성하려면 퍼즐 조각들을 하나 둘씩 맞춰나가야 한다. 인생의 퍼즐 조각들을 하나 둘씩 맞춰나가다 보면 인생이란 퍼즐도 완성되는 날이 오려나...?

calendar

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

Notice

04-20 20:22

Recent Post

Recent Comment

Recent Trackback

Archive

2016. 7. 18. 20:55 Programming/Android



 운영체제 : Windows 8.1 64bit

 개발툴 : Android Studio 1.5

 SDK Version : Min 21, Max 23

 작성날짜 : 2016-07-18

 추가 수정날짜 : 2016-08-05




참고 : 시원한물냉 - (Android) 이미지 용량 줄이기 (Bitmap 관리)


Out of Memory (OOM) 오류로 인해.. 골치가 아파오다 해결방법을 찾았다.


BitmapFactory 를 활용하여 크기를 설정하는 방법!


public static Bitmap getResizedBitmap(Resources resources, int id, int size, int width, int height){
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = size;
Bitmap src = BitmapFactory.decodeResource(resources, id, options);
Bitmap resized = Bitmap.createScaledBitmap(src, width, height, true);
return resized;
}


id 는 이미지 리소스의 id 값


size 는 이미지의 1/N 한큼 이미지를 줄여서 Decoding 하기위한 N의 값


widthheight는 이미지의 크기



디바이스의 이미지를 사용한다면 밑에 방법으로.

public static Drawable getResizeFileImage(String file_route, int size, int width, int height){
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = size;
Bitmap src = BitmapFactory.decodeFile(file_route, options);
Bitmap resized = Bitmap.createScaledBitmap(src, width, height, true);
return new BitmapDrawable(resized);
}



추가


참고 : 유용한 라이브러리 - Glide (이미지 로딩 라이브러리)



위에 방법을 사용하다가 그래도 속도가 느린감이 있어 더 찾아보다 해결책을 찾다.

Glide 라이브러리 완전 좋음!!

posted by Kanais