Android 使用位图后,工厂图像的宽度和高度是否增加?

Android 使用位图后,工厂图像的宽度和高度是否增加?,android,Android,我有一个图像,图像宽度是290,高度是330。当我使用位图工厂转换为位图时,宽度和高度都在增加。我的代码是 mILearnBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.capital_a_1); mILearnBitmap = mILearnBitmap.copy(Bitmap.Config.ARGB_8888, true); mIL

我有一个图像,图像宽度是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。请告知我犯了一些错误,请帮助我。

请使用此功能调整图像大小

     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;

}

请使用此功能调整图像大小

     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;

}
你可以用这个-

createScaledBitmap(bm、int destinationWidth、int destinationHeight、布尔过滤器)

你可以用这个-


createScaledBitmap(bm、int destinationWidth、int destinationHeight、布尔过滤器)

嗨,拉梅什,谢谢你的回复。这里的newWidth和newHeight表示图像的实际大小。这是你想要的新尺寸。表示如果要将图像大小调整为500x300,则调整图像大小newheight=500,newwidth=300,好吗?我称之为此方法,是指在bitmapfactory之前还是之后。请帮助我Ramesh谢谢您的回复。这里newwidth和newheight表示图像的实际大小。不,这是您想要的新大小。表示如果要将图像大小调整为500x300,然后将图像大小调整为newheight=500,newwidth=300,好吗?我称此方法为bitmapfactory之前或之后。请帮助我