0

I download a static map from Google Maps Static API. When I download the image in browser, the size is ok (728x224). You can check the url from below.

But when I try to view it in my android app it's to small (540x166). Of course I could display it with 'centerCrop' but it's not ideal solution. As far as I know, both sizes are in pixels so it should fit perfectly. I log it this way:

 Log.i(TAG, "view size: "+mapPicture.getWidth()+"/"+mapPicture.getHeight());
 Log.i(TAG, "pic size: "+mapPicture.getDrawable().getIntrinsicWidth()+"/"+mapPicture.getDrawable().getIntrinsicHeight());

And the logcat looks like this:

11-29 21:41:37.547: I/DetailsFragment(18064): view size: 728/224
11-29 21:41:37.547: I/DetailsFragment(18064): http://maps.google.com/maps/api/staticmap?center=0,0&zoom=3&size=364x112&scale=2&sensor=false
11-29 21:41:37.547: I/DetailsFragment(18064): pic size: 540/166

I download the image with ImageManager and test on a hdpi device.

So why the downloaded pic has different size than it should?

Edit: When I download an image twice as big, the drawable inside the ImageView is almost the same size as previously: pic size: 540/189

http://maps.google.com/maps/api/staticmap?center=52.2396,21.0174&zoom=14&size=729x225&scale=2&sensor=false

Alex Styl
  • 3,982
  • 2
  • 28
  • 47
Michał Klimczak
  • 12,674
  • 8
  • 66
  • 99

1 Answers1

1

Have you read this from here?

Note: Prior to JELLY_BEAN, this function would not correctly retrieve the final configuration density when the resource ID passed here is an alias to another Drawable resource. This means that if the density configuration of the alias resource is different than the actual resource, the density of the returned Drawable would be incorrect, resulting in bad scaling. To work around this, you can instead retrieve the Drawable through TypedArray.getDrawable. Use Context.obtainStyledAttributes with an array containing the resource ID of interest to create the TypedArray

varevarao
  • 2,186
  • 13
  • 26
  • No i didn't. And I think I'll have to read it 5 times to understand this workaround. But it looks like an exact explanation to my problem. – Michał Klimczak Nov 29 '12 at 21:22
  • So novoda ImageManager downloads image, uses the function you mentioned to get the drawable. And it's the point where the problem occurs. Without changing the code behind the loader I will be unable to resolve it. It scales it down, and when I use `centerCrop` scales up again which results in quality loss. That's weird. Thanks anyway and if you can come up with a solution (and not simply downloading a higher res image), I'd be grateful – Michał Klimczak Nov 29 '12 at 21:35