올해는 머신러닝이다.
[펌]Android BitmapFactory.Options 설명 본문
출처 : http://lsit81.tistory.com/33
며칠전 BitmapFactory.Options.inPurgeable에 대한 내용을 올렸는데요.
1
2
3
4
5
6 |
BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true ; BitmapFactory.decodeFile( "[경로]" , opts); Log.d( "bitmap" , "image width = " + opts.outWidth
+ ", height = " + opts.outHeight + ", mime type = " + opts.outMimeType); |
public boolean inJustDecodeBounds
public int inSampleSize
If set to a value > 1, requests the decoder to subsample the original image, returning a smaller image to save memory. The sample size is the number of pixels in either dimension that correspond to a single pixel in the decoded bitmap. For example, inSampleSize == 4 returns an image that is 1/4 the width/height of the original, and 1/16 the number of pixels. Any value <= 1 is treated the same as 1. Note: the decoder will try to fulfill this request, but the resulting bitmap may have different dimensions that precisely what has been requested. Also, powers of 2 are often faster/easier for the decoder to honor.
그리고 아래와 같이 화면(또는 이미지 뷰) 크기에 따라서 이미지를 sampling하여 사용하면 더욱 효과적으로 사용할 수 있습니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 |
public static Bitmap readImageWithSampling(String imagePath, int targetWidth, int targetHeight,
Bitmap.Config bmConfig) {
// Get the dimensions of the bitmap
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = true ;
BitmapFactory.decodeFile(imagePath, bmOptions);
int photoWidth = bmOptions.outWidth;
int photoHeight = bmOptions.outHeight;
// Determine how much to scale down the image
int scaleFactor = Math.min(photoWidth / targetWidth, photoHeight / targetHeight);
// Decode the image file into a Bitmap sized to fill the View
bmOptions.inPreferredConfig = bmConfig;
bmOptions.inJustDecodeBounds = false ;
bmOptions.inSampleSize = scaleFactor;
bmOptions.inPurgeable = true ;
Bitmap orgImage = BitmapFactory.decodeFile(imagePath, bmOptions);
return image; } |
위쪽 사진이 false 옵션을 주어 이미지를 로드한 상태고
아래 사진이 true 옵션을 주어 이미지를 로드한 상태 입니다.
이미지 로딩 시간은 각각 623ms, 542ms가 걸렸습니다.
public boolean inScaled
When this flag is set, if inDensity
and inTargetDensity
are not 0, the bitmap will be scaled to match inTargetDensity
when loaded, rather than relying on the graphics system scaling it each time it is drawn to a Canvas.
This flag is turned on by default and should be turned off if you need a non-scaled version of the bitmap. Nine-patch bitmaps ignore this flag and are always scaled.
'Android > Tip&Tech' 카테고리의 다른 글
dialog style에서 actionbar 사용하기 (0) | 2013.06.27 |
---|---|
SwichPerference에 widgetlayout 커스터마이징시 check 설정 (0) | 2013.06.25 |
[펌] 나인패치 자동 생성 (0) | 2013.06.14 |
[펌]Android 개발가이드 - View에 할당한 리소스 완전히 해제하기 (0) | 2013.06.13 |
해상도 지원 (0) | 2013.06.03 |