Here you can find the source of scaleToFit(Bitmap bm, float width_Ratio, float height_Ratio)
public static Bitmap scaleToFit(Bitmap bm, float width_Ratio, float height_Ratio)
import android.graphics.Bitmap; import android.graphics.Matrix; public class Main { public static Bitmap scaleToFit(Bitmap bm, float width_Ratio, float height_Ratio) { int width = bm.getWidth(); int height = bm.getHeight(); Matrix matrix = new Matrix(); matrix.postScale((float) width_Ratio, (float) height_Ratio); Bitmap bmResult = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);//from ww w .j a v a2 s . co m return bmResult; } }