Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Large images are not being scaled down. #98

Closed
eggman87 opened this issue Nov 11, 2012 · 9 comments
Closed

Large images are not being scaled down. #98

eggman87 opened this issue Nov 11, 2012 · 9 comments

Comments

@eggman87
Copy link

Not sure if this is supposed to be built into the library or not, but I thought from the documentation that the library will automatically handle scaling the image down based on the imageview size. Even when I set maxWidth and maxHeight to 1000 it still does not load image when the image is too large to be handled by android.

Maybe I am doing something wrong, below is more info on my code:

11-11 11:34:37.132: WARN/OpenGLRenderer(6863): Bitmap too large to be uploaded into a texture (460x5185, max=2048x2048)

My setup:

        ImageLoader imageLoader = ImageLoader.getInstance();

        DisplayImageOptions displayImageOptions = new DisplayImageOptions.Builder()
                .cacheOnDisc()
                .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2)
                .build();

        File cacheDir;
        if (Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {
            cacheDir = new File(Environment.getExternalStorageDirectory(), "data/cache");
        } else {
            cacheDir = getApplicationContext().getCacheDir();
        }
        cacheDir.mkdirs();

        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
                .threadPoolSize(7)
                .threadPriority(Thread.NORM_PRIORITY - 1)
                .discCache(new LimitedAgeDiscCache(cacheDir, 14400))
                .discCacheFileNameGenerator(new HashCodeFileNameGenerator())
                .imageDownloader(new URLConnectionImageDownloader(5 * 1000, 20 * 1000))
                .defaultDisplayImageOptions(displayImageOptions)
                .build();
        imageLoader.init(config);

My Usage:

    private void setImageComposite(ImageComposite composite) {
        mCurrentImage = composite;

        ImageLoader loader = ImageLoader.getInstance();
        String imageUrl = String.format(****ApiConstants.URL_IMAGE_FORMAT, composite.image.hash, composite.image.ext);

        loader.displayImage(imageUrl, mTouchImageView, BaseActivity.getDefaultImageLoadingListener(mEventManager));
    }

My View:

    @InjectView(R.id.tiv_main_image)TouchImageView mTouchImageView;

    <com.****.view.component.TouchImageView
            android:id="@+id/tiv_main_image"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:maxWidth="1000dip"
            android:maxHeight="1000dip"
            android:scaleType="centerCrop"/>
@nostra13
Copy link
Owner

UIL scale original image according to different parameters. One of them is android:scaleType. If you have centerCrop so UIL scales down original image until one of dimensions becomes less than target size (1000x1000 in your case). But you already have image 460x5185, and 460 is less than 1000 so original image isn't scaled.
This logic works for next scale types:

  • MATRIX
  • CENTER
  • CENTER_CROP

If you have scaleType one of these:

  • FIT_CENTER
  • FIT_XY
  • FIT_START
  • FIT_END
  • CENTER_INSIDE
    so UIL scales down original image until both dimensions become less than target size, ie your image will be scaled to 92x1037.

@eggman87
Copy link
Author

Ahhh...my bad. Thanks so much for letting me know, great explanation. I should have tried other scale types. Thanks

@eggman87 eggman87 reopened this Nov 11, 2012
@eggman87 eggman87 reopened this Nov 11, 2012
@eggman87
Copy link
Author

So the scale type fixes the issue. However, I am using a scale type of matrix to be able zoom in and out of image. Can you think of any way's to still have the UIL scale the image down even in matrix mode.

@eggman87
Copy link
Author

Figured out a fix to just override getScaleType to return center inside, and internally use a image matrix to support zooming in and out. Seems to resolve the issues.

@staber
Copy link

staber commented Feb 11, 2013

@eggman87 could you explain your fix further? I'm also using TouchImageView with UIL and getting the same error.

@eggman87
Copy link
Author

@hiv0lt sorry I never got back to you, I do not use github much...I really don't remember the problem much but the source code is available @ https://bitbucket.org/eggman87/ezimgur-open/src/3eba75879df8e266cbb4a08127dc1cfac30114c2/ezimgur/src/com/ezimgur/view/component/TouchImageView.java?at=default if you want to look at it.

@eggman87
Copy link
Author

@hiv0lt re-read the comments, and I remember now. My custom image view was setting scale type to Matrix internally when I was initializing the view (for zooming). However, since this did not work well with UIL. A hack was to return CENTER_INSIDE always for getScaleType which is what the UIL was calling to determine scale type. My guess is that the internals of the image view itself don't call getScaleType to determine what scale type to use and instead just uses the private variable that is set on setScaleType (which would be returned normally on getScaleType).

   @Override
    public ScaleType getScaleType() {
        return ScaleType.CENTER_INSIDE;
    }

@staber
Copy link

staber commented Mar 13, 2013

@eggman87 Ok, thanks. I ended up modifying the UIL library to except a targetSize in the displayImage method. For example:

ImageSize targetSize = new ImageSize(120, 120);
imageLoader.displayImage(imageUrls[position], targetSize, holder.image, options);

You can check out my app here
https://play.google.com/store/apps/details?id=com.hiv0lt.KCCOpro

@jmrboosties
Copy link

Just wanted to comment that this issue really helped me out, to break it down for anyone who wasn't quite clear, use the scaleType centerInside to allow the logic to work, and if you are using a custom ImageView, override the class's getScaleType() method to return ScaleType.CENTER_INSIDE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants