Scaled Bitmap maintaining aspect ratio

后端 未结 12 908
-上瘾入骨i
-上瘾入骨i 2020-11-30 23:49

I would like to scale a Bitmap to a runtime dependant width and height, where the aspect ratio is maintained and the Bitmap fills the entire width

12条回答
  •  Happy的楠姐
    2020-12-01 00:27

    simpler solution : note we set the width to 500 pixels

     public void scaleImageKeepAspectRatio()
        {
            int imageWidth = scaledGalleryBitmap.getWidth();
            int imageHeight = scaledGalleryBitmap.getHeight();
            int newHeight = (imageHeight * 500)/imageWidth;
            scaledGalleryBitmap = Bitmap.createScaledBitmap(scaledGalleryBitmap, 500, newHeight, false);
    
        }
    

提交回复
热议问题