Skip to content

Instantly share code, notes, and snippets.

@gouravd
Last active August 29, 2015 14:10
Show Gist options
  • Save gouravd/60dca91db5d611832510 to your computer and use it in GitHub Desktop.
Save gouravd/60dca91db5d611832510 to your computer and use it in GitHub Desktop.
FixedWidth_VariableHeight_ImageResizing Transformation_Picasso
com.squareup.picasso.Transformation transformation = new com.squareup.picasso.Transformation() {
@Override
public Bitmap transform(Bitmap source) {
int targetWidth = yourview.getWidth();
double aspectRatio = (double) source.getHeight() / (double) source.getWidth();
int targetHeight = (int) (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";
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment