add a custom resizing function #613
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I have a fairly straightforward use case that I couldn't find a good way to implement with Picasso, so I added a new
resizerstage to the decoding pipeline.The use case is: display images as a column of ImageViews in a ListView, with all images scaled to no-larger-than the ListView's width, while preserving aspect ratio. ImageView heights are sized based on the images Picasso loads into them, rather than the other way around. Think web browser, messaging app, or chat room.
A custom transformation can sort of implement this, but not well enough. Some of the images are pretty big, up to 10 megapixels, which means that merely creating the Bitmap to transform takes 20-40MB of RAM per image. Even if that Bitmap is scaled down and recycled, it's a waste of RAM and CPU to create it full-scale. Doing a whole column of these thrashes the GC, then starts failing image loads with OOM, then eventually crashes the whole app with OOM. I want to scale the images at
decodetime, nottransformtime, but without knowing the exact width and height up front.So what I want is the ability to pick image bounds after the image is retrieved and its inherent (full-size) bounds are known, but before it is actually decoded into a Bitmap.
Rather than build something specific to my fit-to-width use case -- e.g.,
resize(maxImageWidth, -1)-- I generalized. I added a new function to the fluent builder pipeline,resizer, to specify a dynamic resizing function. Here's how it works:I believe this would be useful for #226.