2012-02-03 55 views
2

已經我一個圖像,圖像寬度是290和高度是330.when我用位圖工廠轉換成位圖的寬度和高度是increasing.My代碼是,使用位圖工廠圖像後寬度和高度是否增加?

  mILearnBitmap = BitmapFactory.decodeResource(getResources(), 
      R.drawable.capital_a_1); 
     mILearnBitmap = mILearnBitmap.copy(Bitmap.Config.ARGB_8888, true); 
     mILearnPixelsArry = new int[mILearnBitmap.getWidth() * mILearnBitmap.getHeight()]; 
     mILearnBitmap.getPixels(mILearnPixelsArry, 0, mILearnBitmap.getWidth(), 0, 0,mILearnBitmap.getWidth(), mILearnBitmap.getHeight()); 
     Log.d("mILearnPixelsArry", "---" + mILearnPixelsArry.length); 
    Log.d("Width", "---" + mILearnBitmap.getWidth()); 
    Log.d("Height", "---" + mILearnBitmap.getHeight()); 

使用這個代碼後寬度增加至435身高增加到495.請告訴我犯了一些錯誤,請幫助我。

回答

4

請使用此功能來調整圖像

 public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) { 

    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); 
    // matrix.postRotate(90); 
    // recreate the new Bitmap 
    Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, 
      matrix, false); 

    return resizedBitmap; 

} 
+0

嗨Ramesh謝謝你的答覆。這裏newWidth和newHeight意味着圖像的實際尺寸正確 – 2012-02-03 07:14:43

+0

不管你想要什麼新的尺寸。意味着如果你想調整圖像到500x300,然後調整圖像大小newheight = 500,newwidth = 300好嗎? – 2012-02-03 07:16:56

+0

我在這裏調用這個方法,我的意思是在bitmapfactory或after.please幫助我之後 – 2012-02-03 07:24:12

0

您可以使用此 -

Bitmap.createScaledBitmap(BM,INT destinationWidth,INT destinationHeight,布爾過濾器);