Android-Universal-Image-Loader icon indicating copy to clipboard operation
Android-Universal-Image-Loader copied to clipboard

inScaled = false is ignored

Open flamaniac opened this issue 12 years ago • 7 comments

I want load bitmap without any scaling but inScaled is ignored.

BitmapFactory.Options options = new BitmapFactory.Options();
    // for quick memory release
    options.inPurgeable = true;
    options.inInputShareable = true;
    //don't scale
    **options.inScaled  = false;**
    options.inDensity = 0;
    options.inTargetDensity = 0;
    options.inSampleSize =1;
    options.inScreenDensity = 0;
    // ...
    DisplayImageOptions.Builder b = new DisplayImageOptions.Builder();
    **b.imageScaleType(ImageScaleType.NONE);**
    b.decodingOptions(options);
    b.cacheInMemory(false);

    b.cacheOnDisc(true);
    b.showImageForEmptyUri(R.drawable.publication_page_full);
    b.showImageOnFail(R.drawable.publication_page_full);

    // ...
    imgOptions = b.build();

I also try:

ImageSize targetSize = new ImageSize(120, 80); // result Bitmap will be fit to this size
 imageLoader.loadImage(imageUri, targetSize, displayOptions, listner); 

but i dosn't work:/

flamaniac avatar Jan 21 '14 11:01 flamaniac

Anybody solve this?

flamaniac avatar Jan 24 '14 09:01 flamaniac

decodingOptions are considered by Android-Universal-Image-Loader?

flamaniac avatar Jan 24 '14 10:01 flamaniac

I faoud that new Options are created and this why ImageSize is wrong. BaseImage Decoder:

protected ImageFileInfo defineImageSizeAndRotation(InputStream imageStream, ImageDecodingInfo decodingInfo)
            throws IOException {
        Options options = new Options();
        options.inJustDecodeBounds = true;

        BitmapFactory.decodeStream(imageStream, null, options);

        ExifInfo exif;
        String imageUri = decodingInfo.getImageUri();
        if (decodingInfo.shouldConsiderExifParams() && canDefineExifParams(imageUri, options.outMimeType)) {
            exif = defineExifOrientation(imageUri);
        } else {
            exif = new ExifInfo();
        }
        return new ImageFileInfo(new ImageSize(options.outWidth, options.outHeight, exif.rotation), exif);
    }

and you use this image size i decode mathod (line 77) sometime returned size is -1,-1 and after calculate scale is 0. This causes decode error.

flamaniac avatar Jan 24 '14 12:01 flamaniac

My fix:

protected ImageFileInfo defineImageSizeAndRotation(InputStream imageStream, ImageDecodingInfo decodingInfo)
            throws IOException {

        Options options = new Options();
        options.inJustDecodeBounds = true;

        //clone
        Options userOptions = decodingInfo.getDecodingOptions();
        if(userOptions!= null){
            options.inDensity = userOptions.inDensity;
            options.inDither = userOptions.inDither;
            options.inInputShareable = userOptions.inInputShareable;
            options.inPurgeable = userOptions.inPurgeable;
            options.inScaled = userOptions.inScaled;
            options.inScreenDensity = userOptions.inScreenDensity;
            options.inTargetDensity = userOptions.inTargetDensity;
        }

        BitmapFactory.decodeStream(imageStream, null, options);

        ExifInfo exif;
        String imageUri = decodingInfo.getImageUri();
        if (decodingInfo.shouldConsiderExifParams() && canDefineExifParams(imageUri, options.outMimeType)) {
            exif = defineExifOrientation(imageUri);
        } else {
            exif = new ExifInfo();
        }
        return new ImageFileInfo(new ImageSize(options.outWidth, options.outHeight, exif.rotation), exif);
    }

flamaniac avatar Jan 24 '14 12:01 flamaniac

If you read Java docs of DisplayImageOptions.decodingOptions(...) method then you can see answer for your question. Your fix should work for you.

nostra13 avatar Feb 01 '14 22:02 nostra13

Yes, i have read.

  • NOTE: {@link Options#inSampleSize} of incoming options will NOT be considered. Library
  • calculate the most appropriate sample size itself according yo {@link #imageScaleType(ImageScaleType)}
  • options.
    but what about inScaled = false? I think that some option to turn off auto scaling is needed. Thank you for answer. Great and useful lib!

flamaniac avatar Feb 01 '14 23:02 flamaniac

I'm not sure how inScaled option works, its documentation isn't clear for me.

nostra13 avatar Feb 02 '14 09:02 nostra13