Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.HashMap;

import android.graphics.Bitmap;

public class Main {

    public static HashMap<String, Bitmap> splitNumAnimBitmap(Bitmap bitmap, int xPiece, int yPiece) {
        HashMap<String, Bitmap> pieces = new HashMap<String, Bitmap>();
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        float pieceWidth = (float) width / xPiece;
        float pieceHeight = (float) height / yPiece;
        for (int i = 0; i < yPiece; i++) {
            for (int j = 0; j < xPiece; j++) {
                int cellWidth = Math.round(pieceWidth);
                int cellHeight = Math.round(pieceHeight);
                int imgWidth = Math.round(j * pieceWidth);
                int imgHeight = Math.round(i * pieceHeight);
                Bitmap piece = Bitmap.createBitmap(bitmap, imgWidth, imgHeight, cellWidth, cellHeight);
                String bitmapTag = null;
                switch (j) {
                case 0:
                    bitmapTag = "+";
                    break;
                case 1:
                    bitmapTag = 0 + "";
                    break;
                case 2:
                    bitmapTag = 1 + "";
                    break;
                case 3:
                    bitmapTag = 2 + "";
                    break;
                case 4:
                    bitmapTag = 3 + "";
                    break;
                case 5:
                    bitmapTag = 4 + "";
                    break;
                case 6:
                    bitmapTag = 5 + "";
                    break;
                case 7:
                    bitmapTag = 6 + "";
                    break;
                case 8:
                    bitmapTag = 7 + "";
                    break;
                case 9:
                    bitmapTag = 8 + "";
                    break;
                case 10:
                    bitmapTag = 9 + "";
                    break;
                default:
                    break;
                }
                pieces.put(bitmapTag, piece);
            }
        }
        return pieces;
    }
}