Android Bitmap Scale scaleImage(Bitmap image, float scale)

Here you can find the source of scaleImage(Bitmap image, float scale)

Description

scales Bitmap to a decimal

Parameter

Parameter Description
image to scale
scale amount

Return

scaled image

Declaration

public static Bitmap scaleImage(Bitmap image, float scale) 

Method Source Code

//package com.java2s;

import android.graphics.Bitmap;
import android.graphics.Canvas;

import android.graphics.Rect;

public class Main {
    /**//w  ww .j av a2s.  co m
     * scales {@link Bitmap} to a decimal
     * 
     * @param image
     *        to scale
     * @param scale
     *        amount
     * @return scaled image
     */
    public static Bitmap scaleImage(Bitmap image, float scale) {
        Bitmap data = Bitmap.createBitmap((int) (image.getWidth() * scale),
                (int) (image.getHeight() * scale), image.getConfig());
        Canvas canvas = new Canvas(data);
        canvas.drawBitmap(image,
                new Rect(0, 0, image.getWidth(), image.getHeight()),
                new Rect(0, 0, (int) (image.getWidth() * scale),
                        (int) (image.getHeight() * scale)), null);
        return data;
    }
}

Related

  1. scaleBitmap(Bitmap bitmap, int targetwidth)
  2. scaleBitmapIfNeededToSize(Bitmap bitmap, long size)
  3. scaleBitmapKeepRatio(Bitmap bitmap, int dstWidth, int dstHeight)
  4. scaleToTextSize(Bitmap bmp, float textSize)
  5. scaleToScreen(Activity activity, Bitmap bitmap)
  6. scaleImg(Bitmap bitmap, float scale)
  7. scaleImg(Bitmap bitmap, int newWidth, int newHeight)
  8. scaleImg(File file, int newWidth, int newHeight)
  9. getScaleBitmap(Bitmap origialBitmap, int dstWidth, int dstHeight)