4

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?

UMAR-MOBITSOLUTIONS
  • 77,236
  • 95
  • 209
  • 278

2 Answers2

3
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 .

Shailendra Singh Rajawat
  • 8,172
  • 3
  • 35
  • 40
  • well it may be your question, but person asked this question already know what to do next . here you go resizedImage = Bitmap.createScaledBitmap( image, imageWidth, imageHeight, true); – Shailendra Singh Rajawat May 15 '13 at 06:33
  • getWidth() & getHeight() are deprecated now (API 13+). Use the following: `Point size = new Point(); display.getSize(size); int screenWidth = size.x; int screenHeight = size.y;` – Ε Г И І И О Aug 11 '13 at 15:57
2

Create three type of drawable folder drawable-hdpi, drawable-mdpi, drawable-ldpi. Put the diff resolution of images with the same name in these folders. The application will map itself. Another way is to create 9-patch image. 9-patch images adjusts itself as per resolution. and also you have to careful while creating layout. you have to set layout properly. Screen height and width are necesary to set images in which part of screen.

Thanks Deepak

Sunil Kumar Sahoo
  • 53,011
  • 55
  • 178
  • 243