Here you can find the source of crossStretchImageX(Bitmap image, int xsize)
Parameter | Description |
---|---|
image | a parameter |
xsize | a parameter |
public static Bitmap crossStretchImageX(Bitmap image, int xsize)
//package com.java2s; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Rect; public class Main { /**/*from w w w . j a va 2 s . co m*/ * stretches the middle section of the image on the X axis to avoid the borders looking stretched * @param image * @param xsize * @return stretched image */ public static Bitmap crossStretchImageX(Bitmap image, int xsize) { Bitmap cutout = Bitmap.createBitmap((image.getWidth() / 3), image.getHeight(), image.getConfig()); Canvas cutoutc = new Canvas(cutout); Bitmap temp = Bitmap.createBitmap(xsize, image.getHeight(), image.getConfig()); Canvas tempc = new Canvas(temp); cutoutc.drawBitmap(image, new Rect(image.getWidth() / 3, 0, (image.getWidth() / 3) * 2, image.getHeight()), new Rect(0, 0, cutout.getWidth(), cutout.getHeight()), null); tempc.drawBitmap(image, new Rect(0, 0, image.getWidth() / 3, image.getHeight()), new Rect(0, 0, image.getWidth() / 3, temp.getHeight()), null); tempc.drawBitmap( image, new Rect((image.getWidth() / 3) * 2, 0, image.getWidth(), image.getHeight()), new Rect(temp.getWidth() - (image.getWidth() / 3), 0, temp .getWidth(), temp.getHeight()), null); cutout = stretchImage(cutout, xsize - ((temp.getWidth() / 3) * 2), cutout.getHeight()); tempc.drawBitmap( cutout, new Rect(0, 0, cutout.getWidth(), cutout.getHeight()), new Rect(image.getWidth() / 3, 0, temp.getWidth() - (image.getWidth() / 3), image.getHeight()), null); return temp; } /** * 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; } }