Android Bitmap Scale scaleBitmap(Bitmap bitmap, int dstWidth, int dstHeight)

Here you can find the source of scaleBitmap(Bitmap bitmap, int dstWidth, int dstHeight)

Description

scale Bitmap

License

Open Source License

Declaration

public static Bitmap scaleBitmap(Bitmap bitmap, int dstWidth,
            int dstHeight) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import android.graphics.Bitmap;

import android.graphics.Matrix;

public class Main {
    public static Bitmap scaleBitmap(Bitmap bitmap, int dstWidth,
            int dstHeight) {
        int w = bitmap.getWidth();
        int h = bitmap.getHeight();

        Matrix matrix = new Matrix();
        float scaleWidth = ((float) dstWidth / w);
        float scaleHeight = ((float) dstHeight / h);
        matrix.postScale(scaleWidth, scaleHeight);

        return Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix, true);
    }/*from  w w w.  j  a v a  2  s .  c  o  m*/
}

Related

  1. getScalBitmap(Context context, Uri uri, int destW, int destH)
  2. getScalBitmap(String file, int destW, int destH)
  3. getScaledBitmap(Bitmap bitmap, int width, int height)
  4. getScaledBitmapByHeight(Bitmap bm, int newHeight)
  5. scaleBitmap(Bitmap bitmap, int targetwidth)
  6. scaleBitmapIfNeededToSize(Bitmap bitmap, long size)
  7. scaleBitmapKeepRatio(Bitmap bitmap, int dstWidth, int dstHeight)
  8. scaleToTextSize(Bitmap bmp, float textSize)