Android Bitmap Crop cutStretchImage(Bitmap image, int xsize, int ysize)

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

Description

cuts the Bitmap into four corners and stretches the space between them.

Parameter

Parameter Description
image a parameter
xsize a parameter
ysize a parameter

Declaration

public static Bitmap cutStretchImage(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 {
    /**//w  w  w .j a  v  a  2  s  .  c o m
     * cuts the {@link Bitmap} into four corners and stretches the space between them.
     * 
     * @param image
     * @param xsize
     * @param ysize
     * @return
     */
    public static Bitmap cutStretchImage(Bitmap image, int xsize, int ysize) {
        Bitmap data = Bitmap.createBitmap((int) (xsize), (int) (ysize),
                image.getConfig());
        Canvas canvas = new Canvas(data);
        canvas.drawBitmap(
                image,
                new Rect(0, 0, image.getWidth() / 2, image.getHeight() / 2),
                new Rect(0, 0, (int) (image.getWidth() / 2), (int) (image
                        .getHeight() / 2)), null);

        canvas.drawBitmap(
                image,
                new Rect(image.getWidth() / 2, 0, image.getWidth(), image
                        .getHeight() / 2),
                new Rect(xsize - (image.getWidth() / 2), 0, xsize,
                        (int) (image.getHeight() / 2)), null);

        canvas.drawBitmap(
                image,
                new Rect(0, image.getHeight() / 2, image.getWidth() / 2,
                        image.getHeight()),
                new Rect(0, ysize - (image.getHeight() / 2), (int) (image
                        .getWidth() / 2), ysize), null);

        canvas.drawBitmap(
                image,
                new Rect(image.getWidth() / 2, image.getHeight() / 2, image
                        .getWidth(), image.getHeight()),
                new Rect(xsize - (image.getWidth() / 2), ysize
                        - (image.getHeight() / 2), xsize, ysize), null);
        return data;
    }
}

Related

  1. getTrimmedRight(Bitmap img)
  2. getTrimmedRight(Bitmap img, int border)
  3. getTrimmedTop(Bitmap img)
  4. getTrimmedTop(Bitmap img, int border)
  5. cutImg(File file, int newWidth, int newHeight)
  6. cutImg(Bitmap bitmap, int newWidth, int newHeight)
  7. cropCenter(Bitmap bitmap, boolean recycle)
  8. cropCenterBitmap(Bitmap bitmap, int newWidth, int newHeight)
  9. resizeDownAndCropCenter(Bitmap bitmap, int size, boolean recycle)