How to Resize a Bitmap in Android?

后端 未结 16 1980
有刺的猬
有刺的猬 2020-11-22 03:13

I have a bitmap taken of a Base64 String from my remote database, (encodedImage is the string representing the image with Base64):

profileImage          


        
16条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 03:34

      public Bitmap scaleBitmap(Bitmap mBitmap) {
            int ScaleSize = 250;//max Height or width to Scale
            int width = mBitmap.getWidth();
            int height = mBitmap.getHeight();
            float excessSizeRatio = width > height ? width / ScaleSize : height / ScaleSize;
             Bitmap bitmap = Bitmap.createBitmap(
                    mBitmap, 0, 0,(int) (width/excessSizeRatio),(int) (height/excessSizeRatio));
            //mBitmap.recycle(); if you are not using mBitmap Obj
            return bitmap;
        }
    

提交回复
热议问题