How to Resize a Bitmap in Android?

后端 未结 16 2061
有刺的猬
有刺的猬 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:41

    Scale based on aspect ratio:

    float aspectRatio = yourSelectedImage.getWidth() / 
        (float) yourSelectedImage.getHeight();
    int width = 480;
    int height = Math.round(width / aspectRatio);
    
    yourSelectedImage = Bitmap.createScaledBitmap(
        yourSelectedImage, width, height, false);
    

    To use height as base intead of width change to:

    int height = 480;
    int width = Math.round(height * aspectRatio);
    

提交回复
热议问题