0

My application load images from server via HTTP and save it into files. Then I use this code to get Drawable and view it:

File f=new File(path);
if(f.exists()) {
    Bitmap bmp = BitmapFactory.decodeFile(f.getAbsolutePath());
    if(bmp!=null) {
        DisplayMetrics dm = m_activity.getResources().getDisplayMetrics();
        bmp.setDensity(dm.densityDpi);
        Drawable drawable=new BitmapDrawable(context.getResources(), bmp);
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        return drawable;
    }
}

It working fine on Samsung Galaxy S2. But on Samsung Galaxy S4 this images too small. For example:

On S2:

SGS2

On S4:

SGS4

I need to display it equally on all devices with various display's resolution. Is it possible? How to implement this?

BArtWell
  • 4,176
  • 10
  • 63
  • 106
  • Hi - The basic problem is that devices with a HIGHER resolution will make the images appear SMALLER. You need to scale the "intrinsic" size proportionately to your device resolution. – paulsm4 Aug 04 '13 at 21:03
  • @paulsm4, thank you for answer! But can you to explain in a nutshell, how to scale this size proportionately to device resolution? Just in the fewest words. – BArtWell Aug 04 '13 at 21:09
  • 2
    Try this http://stackoverflow.com/questions/17978345/android-image-on-tablets-and-phones/17978396#17978396 – IanB Aug 04 '13 at 21:47

3 Answers3

1

I think I can help you. I had this same kind of problem myself. What you need to do is find how much larger this new screen is than your old one, by first getting the dimensions of your device and putting them in for widthOfStandardDevice and heightOfStandardDevice.Once you know how much larger the new screen is then your old one, you would make two multipliers to multiply everything by. You can now say set the size of the bitmap to bitmap_width and bitmap_height.

DisplayMetrics displaymetrics = new DisplayMetrics();

getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);

height = displaymetrics.heightPixels;

width = displaymetrics.widthPixels;

float widthMultiplier = width/widthOfStandardDevice;

float heightMultiplier = height/heightOfStandardDevice;

int bitmap_width = (int)(600 * widthMultiplier);

int bitmap_height = (int)(800 * heightMultiplier);
JoxTraex
  • 13,423
  • 6
  • 32
  • 45
superuser
  • 731
  • 10
  • 28
1

The basic problem is that devices with a HIGHER resolution will make the images appear SMALLER. You need to scale the "intrinsic" size proportionately to your device resolution.

One good solution (as Sheldon suggested) is to use a Scaled Bitmap:

Community
  • 1
  • 1
paulsm4
  • 114,292
  • 17
  • 138
  • 190
1

you don't have to scale the bitmap, since scaling it up will mean it will use more memory.

instead, you can just tell the imageView how large you wish it to be , and let it show the bitmap in the exact size you wish it to be (use dp).

if you do wish to set the bitmap size yourself, check out this link if image quality is important or this link if speed is more important

Community
  • 1
  • 1
android developer
  • 114,585
  • 152
  • 739
  • 1,270