How to Resize a Bitmap in Android?

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

    Bitmap Resize based on Any Display size

    public Bitmap bitmapResize(Bitmap imageBitmap) {
    
        Bitmap bitmap = imageBitmap;
        float heightbmp = bitmap.getHeight();
        float widthbmp = bitmap.getWidth();
    
        // Get Screen width
        DisplayMetrics displaymetrics = new DisplayMetrics();
        this.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
        float height = displaymetrics.heightPixels / 3;
        float width = displaymetrics.widthPixels / 3;
    
        int convertHeight = (int) hight, convertWidth = (int) width;
    
        // higher
        if (heightbmp > height) {
            convertHeight = (int) height - 20;
            bitmap = Bitmap.createScaledBitmap(bitmap, convertWidth,
                    convertHighet, true);
        }
    
        // wider
        if (widthbmp > width) {
            convertWidth = (int) width - 20;
            bitmap = Bitmap.createScaledBitmap(bitmap, convertWidth,
                    convertHeight, true);
        }
    
        return bitmap;
    }
    

提交回复
热议问题