I know that by using fit() and resize(), the image gets downsized before downloading. Yet for times when listView is used and the images' ratios are varying, I needa set the imageView's layout_width and layout_height as wrap_content, and then use transform() to determine the image's ratio before putting it into the imageView.
eg.
Picasso.with(mContext).load(region.getImage_url()).transform(new Transformation() {
@Override
public Bitmap transform(Bitmap source) {
int targetWidth = getContext().getSharedPreferences(Constants.PREFERENCES, Context.MODE_PRIVATE).getInt(Constants.DEVICE_WIDTH, 0);
double aspectRatio = (double) source.getHeight() / (double) source.getWidth();
int targetHeight = (int) (holder.targetWidth * aspectRatio);
Bitmap result = Bitmap.createScaledBitmap(source, targetWidth, targetHeight, false);
if (result != source) {
// Same bitmap is returned if sizes are the same
source.recycle();
}
return result;
}
@Override
public String key() {
return "transformation" + " desiredWidth";
}
}).into(holder.imageView);
So my problem is will Picasso's transform method also deal with the downsizing of the images before downloading? If not, what is the best approach towards it, while not setting fixed ratio to the listview's imageViews?
the image gets downsized before downloading
how do you expect to do that exactly? – njzk2