2012-01-12 116 views

回答

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); 
相關問題