2017-01-06 1 views
0

웹 URL에서 이미지를 다운로드하고 내 안드로이드 응용 프로그램에 표시하고 있지만 내 요구 사항에 따라 이미지 크기를 조정할 수 없습니다. http://square.github.io/picasso/ - 안드로이드 이미지 크기 조정

private Bitmap decodeFile(File f) { 
    try { 
     //Decode image size 
     BitmapFactory.Options o = new BitmapFactory.Options(); 
     o.inJustDecodeBounds = true; 
     FileInputStream stream1 = new FileInputStream(f); 
     BitmapFactory.decodeStream(stream1, null, o); 
     stream1.close(); 

     //Find the correct scale value. It should be the power of 2. 

     // Set width/height of recreated image 
     final int REQUIRED_SIZE = 285; 

     int width_tmp = o.outWidth, height_tmp = o.outHeight; 
     int scale = 1; 
     while (true) { 
      if (width_tmp/2 < REQUIRED_SIZE || height_tmp/2 < REQUIRED_SIZE) 
       break; 
      width_tmp /= 1; 
      height_tmp /= 1; 
      scale *= 2; 
     } 
     //decode with current scale values 
     BitmapFactory.Options o2 = new BitmapFactory.Options(); 
     o2.inSampleSize = scale; 
     FileInputStream stream2 = new FileInputStream(f); 
     Bitmap bitmap = BitmapFactory.decodeStream(stream2, null, o2); 
     stream2.close(); 
     return bitmap; 
    } catch (FileNotFoundException e) { 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
    return null; 


} 

지금 하나는 내가 사전에 250 * 250도 픽셀 고맙습니다에

+3

"내 요구 사항에 따라 이미지 크기를 조정할 수 없습니다."- 질문을 편집하고 ** 자세한 내용 **을 설명하고 문제가 무엇인지 설명하십시오. ** 특별히 ** 당신이 시도한 코드로 작동하지 않습니다? – CommonsWare

답변

1

시도를 내 이미지 크기를 조정 피카소 라이브러리를 사용하는 방법을 말해 줄 수 있습니다.

매우 쉽게 사용하고 통합 할 수 있으며 정확히 이것을 수행하는 크기 조정 방법이 있습니다.

Picasso.with(context).load(url).resize(250, 250).centerCrop().into(imageView); 

기본적으로 URL을 'url'대신 넣습니다.

관련 문제