我有一个图像,图像宽度是290,高度是330.当我使用位图工厂转换成位图宽度和高度增加。我的代码是,
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.请告诉我有些错误,请帮助我。
答案 0 :(得分: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;
}
答案 1 :(得分:0)
你可以使用它 -
Bitmap.createScaledBitmap(bm,int destinationWidth,int destinationHeight,boolean filter);