Android Bitmap Scale stretchImage(Bitmap image, int xsize, int ysize)

Here you can find the source of stretchImage(Bitmap image, int xsize, int ysize)

Description

Stretches Bitmap to a scale in each direction.

Parameter

Parameter Description
image a parameter
xsize a parameter
ysize a parameter

Declaration

public static Bitmap stretchImage(Bitmap image, int xsize, int ysize) 

Method Source Code

//package com.java2s;

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

import android.graphics.Rect;

public class Main {
    /**/*from   w ww.  j  a v  a2s .co  m*/
     * 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. imageScale(Bitmap bitmap, int dst_w, int dst_h)
  2. scaleBitmap(Bitmap bitmap, float scale)
  3. scaleBitmapDown(Bitmap bitmap)
  4. scaleToFit(Bitmap bm, float width_Ratio, float height_Ratio)
  5. stretchImage(Bitmap image, float xscale, float yscale)
  6. zoomImg(Bitmap bm, int newWidth, int newHeight)
  7. getSmallBitmap(String filePath)
  8. getScaledBitmap(String picturePath, int width, int height)
  9. cleanStretchImage(Bitmap image, int xsize, int ysize)