Last active
August 29, 2015 14:10
-
-
Save gouravd/60dca91db5d611832510 to your computer and use it in GitHub Desktop.
FixedWidth_VariableHeight_ImageResizing Transformation_Picasso
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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