Android Bitmap Scale stretchImage(Bitmap image, float xscale, float yscale)

Here you can find the source of stretchImage(Bitmap image, float xscale, float yscale)

Description

Stretches Bitmap to a scale in each direction.

Parameter

Parameter Description
image a parameter
xscale a parameter
yscale a parameter

Declaration

public static Bitmap stretchImage(Bitmap image, float xscale,
        float yscale) 

Method Source Code

//package com.java2s;

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

import android.graphics.Rect;

public class Main {
    /**/* w  w w . java 2  s . c  om*/
     * Stretches {@link Bitmap} to a scale in each direction.
     * 
     * @param image
     * @param xscale
     * @param yscale
     * @return
     */
    public static Bitmap stretchImage(Bitmap image, float xscale,
            float yscale) {
        Bitmap data = Bitmap.createBitmap(
                (int) (image.getWidth() * xscale),
                (int) (image.getHeight() * yscale), 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() * xscale),
                        (int) (image.getHeight() * yscale)), null);
        return data;
    }

    /**
     * Stretches {@link Bitmap} to a scale in each direction.
     * 
     * @param image
     * @param xsize
     * @param ysize
     * @return
     */
    public static Bitmap stretchImage(Bitmap image, int xsize, int ysize) {
        Bitmap data = Bitmap.createBitmap(xsize, ysize, image.getConfig());
        Canvas canvas = new Canvas(data);
        canvas.drawBitmap(image,
                new Rect(0, 0, image.getWidth(), image.getHeight()),
                new Rect(0, 0, xsize, ysize), null);
        return data;
    }
}

Related

  1. getScaledImageFromUri(Activity activity, Uri uri, int size)
  2. imageScale(Bitmap bitmap, int dst_w, int dst_h)
  3. scaleBitmap(Bitmap bitmap, float scale)
  4. scaleBitmapDown(Bitmap bitmap)
  5. scaleToFit(Bitmap bm, float width_Ratio, float height_Ratio)
  6. stretchImage(Bitmap image, int xsize, int ysize)
  7. zoomImg(Bitmap bm, int newWidth, int newHeight)
  8. getSmallBitmap(String filePath)
  9. getScaledBitmap(String picturePath, int width, int height)