2012-01-12 14 views
1

ギャラリーから写真を選択してもらいたい。ほとんどの写真のサイズが非常に大きいので、私はそれを最も適切な幅に拡大したいと思います。私は絵の道しか知りませんが、それをする方法はありますか?例えばAndroidの画面の幅に合わせて画像のサイズを変更するにはどうすればいいですか?

+0

単に、そのイメージからimageMatrixをフェッチしてから操作をスケーリング適用 – Aakash

答えて

2

、あなたのビットマップはBMPである、とImageViewのがframePhotoの場合:

 int iWidth=bmp.getWidth(); 
     int iHeight=bmp.getHeight(); 

     Display display = getWindowManager().getDefaultDisplay(); 
     DisplayMetrics dm = new DisplayMetrics(); 
     display.getMetrics(dm); 

     int dWidth=dm.widthPixels; 
     int dHeight=dm.heightPixels; 

     float sWidth=((float) dWidth)/iWidth; 
     float sHeight=((float) dHeight)/iHeight; 

     if(sWidth>sHeight) sWidth=sHeight; 
     else sHeight=sWidth; 

     Matrix matrix=new Matrix(); 
     matrix.postScale(sWidth,sHeight); 
     newImage=Bitmap.createBitmap(bmp, 0, 0, iWidth, iHeight, matrix, true); 
     framePhoto.setImageBitmap(newImage); 
関連する問題