Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.graphics.Bitmap;

import java.util.ArrayList;
import java.util.List;

public class Main {
    /**
     * Method to split an image vertically into a List
     * composed by {@code piecesNum} of Bitmaps.
     *
     * @param source    The source Bitmap.
     * @param piecesNum int that represents the number of pieces.
     * @return The List of Bitmap's pieces.
     */
    public static List<Bitmap> splitImageVertically(Bitmap source, int piecesNum) {
        List<Bitmap> pieces = new ArrayList<>();
        int height = source.getHeight() / piecesNum;
        int start = 0;
        for (int i = 0; i < piecesNum; i++) {
            Bitmap pieceBitmap = Bitmap.createBitmap(source, 0, start, source.getWidth() - 1, height - 1);
            pieces.add(pieceBitmap);
            start = (source.getHeight() / piecesNum) * (i + 1);
        }
        return pieces;
    }
}