Returns the number of horizontal subdivisions the argument image needs to be divided into to respect argument size - Java java.lang

Java examples for java.lang:Math Number

Description

Returns the number of horizontal subdivisions the argument image needs to be divided into to respect argument size

Demo Code


import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class Main{
    /**/*from w ww  . j a  v  a 2s  . c o  m*/
     * Returns the number of horizontal subdivisions the argument image needs to
     * be divided into to respect argument maxTexDim size
     * 
     * @param sourceImg
     * @param maxTexDim
     * @return the number of texture matrices
     */
    public static int getNumTextureMatrixPerRow(Image sourceImg,
            int maxTexDim) {
        if (null != sourceImg) {
            //define number of needed subdivisions
            int numSubTexPerRow = 0, imgW = sourceImg.getWidth();

            while (maxTexDim * numSubTexPerRow < imgW)
                ++numSubTexPerRow;

            return numSubTexPerRow;
        }

        return -1;
    }
}

Related Tutorials