2017-01-06 4 views
0

私は、Web URLから画像をダウンロードしていて、アンドロイドアプリケーションに表示していますが、自分の要件に従って画像のサイズを変更できません。 http://square.github.io/picasso/ -Android Image Resizing

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'の代わりに入れます。