How to scale the image in accordance with the screen resolution?

friends

I am using the following code for resizeImage

 private Bitmap resizeImage( final Bitmap image) {
        Bitmap resizedImage = null;
        if(image != null)
        {
        int maxHeight = 80; //actual image height coming from internet
        int maxWidth = 150; //actual image width coming from internet

        int imageHeight = image.getHeight();
        if ( imageHeight > maxHeight )
        imageHeight = maxHeight;
        int imageWidth = (imageHeight*image.getWidth()) / image.getHeight();
        if ( imageWidth > maxWidth ) {
        imageWidth = maxWidth;
        imageHeight = (imageWidth*image.getHeight()) / image.getWidth();
        }
        resizedImage = Bitmap.createScaledBitmap( image, imageWidth, imageHeight, true);
        }
        return resizedImage;
        }

from the Internet. now it works fine on a high resolution screen, but on a small screen no one tells me what should I do to display an image in accordance with the screen resolution?

+3
source share
2 answers
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int screenWidth = display.getWidth();
int screenHeight = display.getHeight();

so that you with an hv screen with a width of n height with you, you can display the image in accordance with the screen resolution.

+3
source

drawable-hdpi, drawable-mdpi, drawable-ldpi. . . - 9--. 9-- . . . , .

+2

All Articles