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

Returning a bitmap #55

Closed
shism2 opened this issue Jan 5, 2014 · 9 comments
Closed

Returning a bitmap #55

shism2 opened this issue Jan 5, 2014 · 9 comments
Labels

Comments

@shism2
Copy link

shism2 commented Jan 5, 2014

Is there a way to return a bitmap using glide? How would I go about this?

@lalith-b
Copy link

lalith-b commented Jan 6, 2014

you should use ImageViewTarget class/subclass to get the bitmap from glide.

@shism2
Copy link
Author

shism2 commented Jan 11, 2014

Do you have an example?

@sjudd
Copy link
Collaborator

sjudd commented Jan 12, 2014

As @deathlord87 suggested, use a custom target. https://github.com/bumptech/glide/blob/master/library/src/com/bumptech/glide/presenter/target/SimpleTarget.java is a great place to start. The line would look something like:

Glide.load(yourModel).into(new SimpleTarget() {
    @Override
    public void onImageReady(Bitmap bitmap) {
        doSomethingWithBitmapHere(bitmap);
    }

    @Override
    public int[] getSize() {
        return new int[] { desiredWidth, desiredHeight };
    }
}

@shism2
Copy link
Author

shism2 commented Jan 12, 2014

  1. I have to specify a width and height ?
  2. Is the caching still done if I do it this way?
  3. If a bitmap is cached is there a way to return the local disk url or return it from the bitmap pool or return it from the memory cache?

@shism2
Copy link
Author

shism2 commented Jan 12, 2014

  1. Is there a way to check if a bitmap is already cached?

@sjudd
Copy link
Collaborator

sjudd commented Jan 17, 2014

  1. You do need to specify the target width and height of the bitmap you want. This is done so we can downsample the bitmap appropriately. If you blindly load full size images you could easily load an image large enough to cause an OOM by itself.
  2. Changing the target doesn't change anything about how the load occurs, so all the normal caching will occur.
  3. There isn't currently a way to specify a specific cache to get the image from.
  4. All of the caches in Glide are by default LRU caches, so you can't guarantee that an image will not be evicted from a cache between the time you call isInCache and the time you try to get the image from the cache. With this caveat it would be possible to add a check to see if an image is in the disk cache.

@marcyliao
Copy link

Hi,
I used the Simple Target code but I don't know why the onImageReady never called. My images are from Internet. Before, I used .into(ImageView) and I could see the image.

Any ideas? I will try to debug your source code.

@bumpserver
Copy link

You're probably doing .into(SimpleTarget);? For anything other than
.into(ImageView) you need to do .into(Target).with(Context); if you dont
add the with context part, you don't complete the request so the load never
starts

I know its a flaw in the api (I regularly forget myself) and it has been
addressed in the 3.0 alpha branch.

@marcyliao
Copy link

Yes, I just found that a few minutes ago..
Thanks..

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

No branches or pull requests

6 participants