2014-02-19 2 views

답변

0

decodeSampledBitmapFromUri 방법을보세요. 사진을로드 한 방법입니다.

귀하의 경우 낮은 reqWidthreqHeight을 전달하므로 저해상도 이미지를 얻을 수 있습니다. 더 좋은 이미지 (화면 너비 및 높이와 같은)를 위해 더 큰 크기를 전달하거나 전체 이미지에 을 사용하십시오.

0

BimapFactory를 사용할 수 있습니다. 파일의 경로와 필요한 높이와 너비가 있다고 가정합니다.

BitmapDrawable b = decodeSampleBitmapFromFile(getActivity(), path, pictureWidth, pictureHeight); 
view.setImageDrawable(b) 
: 여기에서

public static BitmapDrawable decodeSampledBitmapFromFile(Activity a, String path, float reqHeight, float reqWidth){ 
    final BitmapFactory.Options options = new BitmapFactory.Options(); 
    //you are not really creating the bitmap now but just calculating it's bounds 
    options.inJustDecodeBounds = true; 
    BitmapFactory.decodeFile(path, options); 

    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); 
    options.inJustDecodeBounds = false; 

    //options now holds the size needed to decode 
    Bitmap bitmap = BitmapFactory.decodeFile(path, options); 

    return new BitmapDrawable(a.getResources(), bitmap); 
} 

public static int calculateInSampleSize(BitmapFactory.Options options, float reqWidth, float reqHeight){ 
    float srcWidth = options.outWidth; 
    float srcHeight = options.outHeight; 

    int sampleSize = 1; 

    if(srcHeight > reqHeight || srcWidth > reqWidth){ 
     final float halfHeight = srcHeight/2; 
     final float halfWidth = srcWidth/2; 

     while((halfHeight/sampleSize) > reqHeight && (halfWidth/sampleSize) > reqWidth){ 
      sampleSize *= 2; 
     } 
    } 

    return sampleSize; 
} 

그것 (view.setImageDrawable (drawble)를 통해)보기로 BitmapDrawble를 할당 한 간단

는 사용을 작동하게하는

관련 문제