Back to project page Gazetti_Newspaper_Reader.
The source code is released under:
MIT License
If you think the Android project Gazetti_Newspaper_Reader listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package in.sahildave.gazetti.util; // w w w.j a v a 2 s. c om /** * Created by sahil on 23/11/14. */ import android.graphics.Bitmap; import com.squareup.picasso.Transformation; /** * Transformate the loaded image to avoid OutOfMemoryException */ public class BitmapTransform implements Transformation { int maxWidth; int maxHeight; public BitmapTransform(int maxWidth, int maxHeight) { this.maxWidth = maxWidth; this.maxHeight = maxHeight; } @Override public Bitmap transform(Bitmap source) { int targetWidth, targetHeight; double aspectRatio; if (source.getWidth() > source.getHeight()) { targetWidth = maxWidth; aspectRatio = (double) source.getHeight() / (double) source.getWidth(); targetHeight = (int) (targetWidth * aspectRatio); } else { targetHeight = maxHeight; aspectRatio = (double) source.getWidth() / (double) source.getHeight(); targetWidth = (int) (targetHeight * aspectRatio); } Bitmap result = Bitmap.createScaledBitmap(source, targetWidth, targetHeight, false); if (result != source) { source.recycle(); } return result; } @Override public String key() { return maxWidth + "x" + maxHeight; } }