how to scale image according to screen resolution?

UMAR-MOBITSOLUTIONS picture UMAR-MOBITSOLUTIONS · May 6, 2011 · Viewed 8.9k times · Source

friends,

i am using following code to 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;
        }

coming from internet. now it works fine on high resolution screen but on small screen it does not any one guide me what should i do to display image according to screen resolution?

Answer

Shailendra Singh Rajawat picture Shailendra Singh Rajawat · May 6, 2011
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int screenWidth = display.getWidth();
int screenHeight = display.getHeight();

so wen you hv screen width n height with you, you can display image according to screen resolution .