gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 08:11:30 24 4
gpt4 key购买 nike

我有一张图片,图片宽度为 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;

}

关于android - 使用位图工厂后图像的宽度和高度是否增加?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9124693/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com