2011-05-10 50 views
1

當我從圖庫中獲取圖片時,圖片看起來很模糊。我使用以下代碼將其大小調整爲250w * 300h:在android中的圖片模糊

 if(bm!=null) 
     { 
      int width = bm.getWidth(); 
      int height = bm.getHeight(); 
      float scaleWidth = ((float) newWidth)/width; 
      float scaleHeight = ((float) newHeight)/height; 
      // create a matrix for the manipulation 
      Matrix matrix = new Matrix(); 
      // resize the bit map 
      matrix.postScale(scaleWidth, scaleHeight); 
      // recreate the new Bitmap 
      resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix,true); 
     } 
    } 
    catch(Exception e) 
    { 
     e.printStackTrace(); 
    } 
} 

我該如何解決這個問題?

回答

1

你不需要矩陣操作只需用

resizedBitmap = Bitmap.createScaledBitmap(bm, w, h, true); 

我不知道你是怎麼計算newWidth和newHeight,但它可能是你的新縮放的位圖太小,然後在視圖streaches因此模糊。