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

标签 android

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

相关文章:

android - 抽屉导航不关闭

android - whatsapp 超链接 - 结合 whatsapp ://send? 与 intent://send/

android - ionic 构建安卓 :CordovaLib:compileDebugJavaWithJavac

android - 如何访问我的 Android 项目中的另一个 APK 文件?

android - 如何在同一列表项中同时显示字符串和编辑文本字段?

Android:想要在相机预览上放置剪影叠加

java - Android - recyclerView返回多次相同的项目

Android:发送带有来自 ImageView 的图像的电子邮件

java - 编码字符串的 Http get/post

android - 如何在 Android 布局中显示 Html 内容?