2012-02-03 28 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,布尔过滤器);