2012-08-01 3 views
0

맞춤 목록보기 항목을 만들고 있습니다. 확장 onDraw 메서드를보고 오버라이드합니다.Android 비트 맵 성능이 좋지 않은 고해상도 화면의 사용자 정의보기

private Bitmap bmpScaledBackground; //with size:(screenWidth , screenHeight/4) 
@Override 
public void onDraw(Canvas canvas){ 
    canvas.drawBitmap(bmpScaledBackground , 0 , 0 , null); 
    //...more of that 
} 

지금까지 Galaxy SII와 같은 일반 휴대 전화에서는 꽤 잘 작동합니다.

하지만 Galaxy Nexus의 경우 성능이 떨어집니다. GN (1280x720)의 큰 해상도 때문이라고 생각합니다.

위의 경우 배경 비트 맵 (bmpScaledBackground) 만 720x320 크기로 그리기에는 시간이 오래 걸립니다. OOM의 위험은 말할 것도 없습니다.

사용자 지정보기를 만들기 위해 더 확장 가능한 방법 (SurfaceView 및 OpenGL 제외)이 있는지 물어 씁니다.

영어 불쌍한 학생들에게 죄송합니다.

답변

0

내 옵션 : 1, 'xxx.9.png'형식의 사진 자료를 사용하십시오. 2, 압축 비트 맵을 사용하십시오.

//get opts 
    BitmapFactory.Options opts = new BitmapFactory.Options(); 
    opts.inJustDecodeBounds = true ; 
    Bitmap bitmap = BitmapFactory.decodeFile(imageFile, opts); 

    //get a appropriate inSampleSize 
    public static int computeSampleSize(BitmapFactory.Options options, 
     int minSideLength, int maxNumOfPixels) { 
    int initialSize = computeInitialSampleSize(options, minSideLength, 
      maxNumOfPixels); 
    int roundedSize; 
    if (initialSize <= 8) { 
     roundedSize = 1 ; 
     while (roundedSize < initialSize) { 
      roundedSize <<= 1 ; 
     } 
    } else { 
     roundedSize = (initialSize + 7)/8 * 8 ; 
    } 
    return roundedSize; 
} 

private static int computeInitialSampleSize(BitmapFactory.Options options, 
     int minSideLength, int maxNumOfPixels) { 
    double w = options.outWidth; 
    double h = options.outHeight; 
    int lowerBound = (maxNumOfPixels == - 1) ? 1 : 
      (int) Math.ceil(Math.sqrt(w * h/maxNumOfPixels)); 
    int upperBound = (minSideLength == - 1) ? 128 : 
      (int) Math.min(Math.floor(w/minSideLength), 
      Math.floor(h/minSideLength)); 
    if (upperBound < lowerBound) { 
     // return the larger one when there is no overlapping zone. 
     return lowerBound; 
    } 
    if ((maxNumOfPixels == - 1) && 
      (minSideLength == - 1)) { 
     return 1 ; 
    } else if (minSideLength == - 1) { 
     return lowerBound; 
    } else { 
     return upperBound; 
    } 
} 
//last get a well bitmap. 
BitmapFactory.Options opts =new BitmapFactory.Options(); 
opts.inSampleSize = inSampleSize;// inSampleSize should be index value of 2. 
Bitmap wellbmp =null; 
wellbmp = BitmapFactory.decodeResource(getResources(), mImageIds[position],opts); 

행운을 빈다! ^ -^