Android-Universal-Image-Loader
Android-Universal-Image-Loader copied to clipboard
ImageSize not matching set width, height: 1px off.
I'm not sure if this is expected to happen:
Input a square image 640x640px then load sync with ImageSize 200x200 and getting a 199x199 image.
Setting ImageSize to 300x300 gives a 300x300 image, which is expected.
My usage is:
private void initializeImage() {
Bitmap b = getBitmap(imageUri, 200, 200);
Log.d(TAG, "albertBitmap: " + b.getWidth() + ", " + b.getHeight());
imageView.setImageBitmap(b);
}
private Bitmap getBitmap(Uri uri, int width, int height) {
ImageLoader mImageLoader = App.getUIL();
DisplayImageOptions options = new DisplayImageOptions.Builder()
.imageScaleType(ImageScaleType.EXACTLY)
.considerExifParams(true)
.cacheOnDisk(true)
.build();
// ImageSize resizes image to a fitting maximum of width and height
// Note that ImageSize does not crop the image.
ImageSize size = new ImageSize(width, height);
return mImageLoader.loadImageSync(uri.toString(), size, options);
}
Log results:
D/DetailsActivity﹕ albertBitmap: 199, 199
I'm using 1.9.2
It seems some problem with scale calculations in BaseImageDecoder (line 188-191). But it's hard to say how to fix it.
@nostra13 thanks for looking into this. I don't think this is exceptionally important, though would be nice to fix or at least know where problem comes from.
Looks like a precision issue. Maybe a loss here: https://github.com/nostra13/Android-Universal-Image-Loader/blob/70ddbbc67fd514915234ce0088bc9aabc9d6186a/library/src/com/nostra13/universalimageloader/utils/ImageSizeUtils.java#L191
Did you have logging enabled? Can you show log like Scale subsampled image (...) to ... (scale = ...) [...] about this image?